admin管理员组文章数量:1332339
I am new to Jade/Pug template engine used in Express I need to print out the name property of a list objects contained in an associative array passed as parameter to the pug template from an express route module.
I am trying in different ways like
each element in listOfElements
p #{element.name}
where listOfElements is the name of the passed parameter
But I can't get the desired result
UPDATE
I am now trying to follow the doc which only provides a UL
example (not what I need).
According to the doc I am going like this
ul
each element in listOfElements
li = element.name
What I get on the rendered page is a list in which each bullet contains the " = element.name" text
I am new to Jade/Pug template engine used in Express I need to print out the name property of a list objects contained in an associative array passed as parameter to the pug template from an express route module.
I am trying in different ways like
each element in listOfElements
p #{element.name}
where listOfElements is the name of the passed parameter
But I can't get the desired result
UPDATE
I am now trying to follow the doc which only provides a UL
example (not what I need).
According to the doc I am going like this
ul
each element in listOfElements
li = element.name
What I get on the rendered page is a list in which each bullet contains the " = element.name" text
Share Improve this question edited Oct 23, 2016 at 12:17 Andrea Sindico asked Oct 23, 2016 at 8:09 Andrea SindicoAndrea Sindico 7,4407 gold badges49 silver badges87 bronze badges 9- pugjs/language/iteration.html – hjpotter92 Commented Oct 23, 2016 at 8:39
- What output are you getting? – hjpotter92 Commented Oct 23, 2016 at 8:42
- see the update thank you – Andrea Sindico Commented Oct 23, 2016 at 12:18
-
It should be
li=
and notli =
– hjpotter92 Commented Oct 23, 2016 at 12:20 - wow I didn't get it is sensitive to white spaces. Post the answer – Andrea Sindico Commented Oct 23, 2016 at 19:30
1 Answer
Reset to default 5Going by the documentation on Pug website regarding iterations, you can get buffered code by placing an =
right after the tag name. The docs for the same lie here. Therefore, in your second attempt, the following will work:
ul
each element in listOfElements
li= element.name
However, as to the first attempt, I tried the following code, and it gave me the expected output (as shown after the snippet):
ul
each val in [{1:'a'}, {1:2}, {1:3}, {1:4}, {1:5}]
li #{val[1]}
outputs:
<ul>
<li>a</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
本文标签: javascriptprinting elements of array in PugStack Overflow
版权声明:本文标题:javascript - printing elements of array in Pug - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742328708a2454249.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论