javascript - 循环遍历 nunjucks 中的对象?

标签 javascript json nunjucks

我有一个名为“list.json”的文件,设置如下:

{
  "thing1": "Thing1",
  "thing2": "Thing2",
  "thing3": "Thing3"
}

我怎样才能遍历这个?我想做类似的事情:

{% for item in list%}
  <option>{{ thing }}</option>
{% endfor %}

最佳答案

你可以试试看

{% for key, item in list%}
  <option>{{ item }}</option>
{% endfor %}

关于javascript - 循环遍历 nunjucks 中的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34902813/

相关文章:

javascript - 使用事件通过 Analytics 跟踪下载按钮点击

javascript - 需要将包含img url的Json链接放在<img ng-src中

json - 将部分json查询结果存储在powershell中的变量中

c# - 如何使用名为 "object"的变量名?

intellij-idea - 将 Nunjucks 与 IntelliJ IDEA/Webstorm 集成

javascript - 从 NPM( Node 模块)解析 nunjucks 模板?

javascript - 如何在数据表中启用复制、PDF、Excel 按钮

javascript - Node.js 请求 promise jar cookie 不起作用

javascript - 如何在 Three.Js 中添加按钮作为 UI 元素

templates - 如果... !true nunjucks 中的条件渲染