我想打印出一个div,仅用于每个循环的前两次迭代。我怎样才能在玉石上做类似
的事情counter = 0
for each tab in tabs
if (counter == 0)
div.nav-header NAVIGATION
counter++
else if (counter == 1)
div.nav-header MY GROUPS
counter++
答案 0 :(得分:0)
查看case
块:http://jade-lang.com/reference/
- var counter = 0
each tab in tabs
case counter
when 0
div.nav-header NAVIGATION
when 1
div.nav-header MY GROUPS
- counter++
当然tabs
应该是您传递给Jade Engine的Array变量。
更清洁的替代方案可以使用数组索引:
each tab, counter in tabs
case counter
when 0
div.nav-header NAVIGATION
when 1
div.nav-header MY GROUPS
或者更短的if
阻止(但我希望case
一个用于提高可读性
each tab, counter in tabs
if counter === 0
div.nav-header NAVIGATION
if counter === 1
div.nav-header MY GROUPS