V
V
Violetta Morozova2016-09-07 17:52:41
JavaScript
Violetta Morozova, 2016-09-07 17:52:41

How to set a loop in jade with a repetition of no more than, for example, 5 times?

I'm a little familiar with cycles in js, but I'm still confused in jade. Here I sit - stupid.
It is necessary to me, means, to deduce the list from 5 elements. At the moment, I just form a list like this:

ul
    - each subitem in item.items
        li
            a(href="#" title="#{subitem.name}")
                | !{subitem.name}

What and where to write in each so that jade displays a list of no more than five elements.
PS Please don't post links to google or jade-lang, which is already pugjs. I've been there. Do not judge strictly - the end of the working day.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kravchenko, 2016-09-07
@vilka_2009

ul
    - each subitem in item.items.slice(0,5)
        li
            a(href="#" title="#{subitem.name}")
                | !{subitem.name}

H
HamSter, 2016-09-07
@HamSter007

- var x = 5;
- var items = ['item1', 'item2', 'item3','item4','item5','item6','item7']
div  
  ul  
  - for (var i=0; i<x; i++) {     
        li
          a(href="#").link= items[i]
  - }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question