【问题标题】:How to render array parameter in pug file如何在 pug 文件中呈现数组参数
【发布时间】:2021-12-09 06:53:56
【问题描述】:

我想使用 pug 模板文件来呈现 html。 这是哈巴狗文件 temp1.pug

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

我想通过参数friends中的数组来渲染pug文件:

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

它应该有这样的输出:

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

但实际输出是:

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

似乎 pug 编译器完全忽略了我的数组输入。有没有办法使用数组参数来渲染这个页面?

【问题讨论】:

    标签: javascript html node.js pug


    【解决方案1】:

    请试试这个:

    each val,index in friends
    

    【讨论】:

    • 它有效。谢谢
    猜你喜欢
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 2020-10-08
    • 1970-01-01
    • 2019-02-28
    • 2018-11-22
    • 2021-09-18
    • 1970-01-01
    相关资源
    最近更新 更多