简体   繁体   English

如何在 pug 文件中渲染数组参数

[英]How to render array parameter in pug file

I want to use a pug template file to render html.我想使用 pug 模板文件来呈现 html。 Here is the pug file temp1.pug :这是pug文件temp1.pug

h1 hello!
p here is my friends:
  ul
    each val,index in !{friends}
      li='friend'+(index+1)+ ' ' + val

I want to render the pug file by using array in parameter friends:我想通过在参数朋友中使用数组来渲染 pug 文件:

const templateRender = pug.compileFile('./temp1.pug');
console.log(templateRender({friends:['aaa','bbb']}));

It is supposed to have the output like:它应该有如下输出:

<h1>hello!</h1>
<p>here is my friends:
<ul>
<li>friend 1: aaa</li>
<li>friend 2: bbb</li>
</ul>
</p>

but the actual output is:但实际输出是:

<h1>hello!</h1>
<p>here is my friends:
<ul></ul>
</p>

It seemed that pug complier completely ignore my array input.似乎 pug 编译器完全忽略了我的数组输入。 Is there any idea to use array parameters to render this page?有什么想法可以使用数组参数来呈现此页面吗?

请试试这个:

each val,index in friends

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM