javascript - printing elements of array in Pug - Stack Overflow

I am new to JadePug template engine used in ExpressI need to print out the name property of a list ob

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 not li = – 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
 |  Show 4 more ments

1 Answer 1

Reset to default 5

Going 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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742328708a4423274.html

相关推荐

  • javascript - printing elements of array in Pug - Stack Overflow

    I am new to JadePug template engine used in ExpressI need to print out the name property of a list ob

    7小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信