Foreach loop in jade (node.js template engine)


Question

Ok, I am getting an associative array from node server and trying to render it in Jade. I obviously need a foreach loop, but nothing seems to work! I tried these both codes:

- foreach row in rows {
    li= row
- }

and

- rows.forEach(function(item)) {
    li= item
- })

the array I am passing is called "rows". Any idea why this is not working? I am getting this error:

500 SyntaxError: Unexpected identifier

and, with the second code:

500 SyntaxError: Unexpected token )
1
29
10/3/2012 5:58:59 AM

Accepted Answer

try

each item in rows
    li= item
48
9/11/2012 9:25:04 AM

Your second example would work except you have a small syntax error in it - an extra parentheses, it should be:

- rows.forEach(function(item) {
  li= item
- })

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon