jade 中的 Foreach 循环(node.js 模板引擎)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12366402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Foreach loop in jade (node.js template engine)
提问by Sagiv Ofek
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:
好的,我从节点服务器获取关联数组并尝试在 Jade 中呈现它。我显然需要一个 foreach 循环,但似乎没有任何效果!我试过这两个代码:
- 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 )
回答by Sagiv Ofek
try
尝试
each item in rows
li= item
回答by frontsidebus
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
- })

