A
A
Alexey Kartushin2016-11-05 23:31:58
Pug
Alexey Kartushin, 2016-11-05 23:31:58

How to sort elements by lists in jade?

I have this array of objects:

categories: [{
        link: "#cat1",
        name: "Категория1",
      },{
        link: "#cat2",
        name: "Категория2",
      },{
        link: "#cat3",
        name: "Категория3",
      },{
        link: "#cat4",
        name: "Категория4",
      },{
        link: "#cat5",
        name: "Категория5",
      },{
        link: "#cat6",
        name: "Категория6",
      },{
        link: "#cat7",
        name: "Категория7",
      },{
        link: "#cat8",
        name: "Категория8",
      },{
        link: "#cat9",
        name: "Категория9",
      }]

How to run it through jade so that at the output I have lists in each of which have 4 elements and in the last one everything remaining? (as in this example, it should get two complete lists of 4 elements and one incomplete list with one element).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Velichko, 2016-11-12
@Alovinglol

Nobody is stopping you from using javascript

- var data = {categories: [{ link: "#cat1", name: "Категория1", },{ link: "#cat2", name: "Категория2", },{ link: "#cat3", name: "Категория3", },{ link: "#cat4", name: "Категория4", },{ link: "#cat5", name: "Категория5", },{ link: "#cat6", name: "Категория6", },{ link: "#cat7", name: "Категория7", },{ link: "#cat8", name: "Категория8", },{ link: "#cat9", name: "Категория9" }]};

- var categories;
- while (data.categories.length > 0)
  - categories = data.categories.splice(0,4);
  ul
    each category in categories
      li: a(href=category.link)= category.name

codepen.io/Zoxon/pen/GNZNWr?editors=1000

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question