【发布时间】:2019-02-12 18:45:25
【问题描述】:
我正在尝试使用把手迭代 JSON 数组中的每个项目。但是我无法显示下面的任何 JSON 数据。这是我的代码:
HTML
{{#each entries}}
<div class="entry">
<h1>{{day}}</h1>
<div class="body">
{{content}}
</div>
</div>
{{/each}}
...
<script>
var entries = {
entries: [
{
day: "Day 1",
content: "THIS is TEST CONTENT"
},
{
day: "Day 2",
content: "THIS is TEST CONTENT2"
}
]
};
</script>
我尝试了同样的方法 - http://tryhandlebarsjs.com/ 并且效果很好,似乎有什么问题?谢谢。
【问题讨论】:
-
请同时显示您正在编译和渲染模板的部分
-
试试
#each entries.entries -
你试过
this。例如。{{this.day}},{{this.content}}? -
谢谢,但是 entries.entries 不起作用,this.day 也不起作用。至于编译,我在网上尝试了一些不同的建议,但都没有奏效,所以我希望有人能给出正确的编译和渲染方法?
-
someone could show the correct way of compiling and rendering?handlebarsjs.com
标签: javascript json handlebars.js