Javascript 在无名对象或数组上实现handlebar.js循环
所有Javascript 在无名对象或数组上实现handlebar.js循环,javascript,handlebars.js,Javascript,Handlebars.js,所有handlebar示例都使用数组或对象名实现循环,但我的json数组没有任何名称 我的数据类似于: [ {"$id":"1","SiteItemID":1,"Title":"Title 1","CreateDate":"2014-06-19T14:12:22.157"}, {"$id":"2","SiteItemID":2,"Title":"Title 2","CreateDate":"2014-06-19T14:12:22.157"}, {"$id":"2","Si
handlebar
示例都使用数组或对象名实现循环,但我的json数组没有任何名称
我的数据类似于:
[
{"$id":"1","SiteItemID":1,"Title":"Title 1","CreateDate":"2014-06-19T14:12:22.157"},
{"$id":"2","SiteItemID":2,"Title":"Title 2","CreateDate":"2014-06-19T14:12:22.157"},
{"$id":"2","SiteItemID":3,"Title":"Title 3","CreateDate":"2014-06-19T14:12:22.157"},
]
{{#each object}}
<tr data-id="{{this.SiteItemID}}">
<td class="title col-xs-8">
{{this.Title}}
</td>
<td class="date text-right col-xs-2">
{{this.CreateDate}}
</td>
</tr>
{{else}}
No Content
{{/each}}
我想在表行中使用它们,我的html类似于:
[
{"$id":"1","SiteItemID":1,"Title":"Title 1","CreateDate":"2014-06-19T14:12:22.157"},
{"$id":"2","SiteItemID":2,"Title":"Title 2","CreateDate":"2014-06-19T14:12:22.157"},
{"$id":"2","SiteItemID":3,"Title":"Title 3","CreateDate":"2014-06-19T14:12:22.157"},
]
{{#each object}}
<tr data-id="{{this.SiteItemID}}">
<td class="title col-xs-8">
{{this.Title}}
</td>
<td class="date text-right col-xs-2">
{{this.CreateDate}}
</td>
</tr>
{{else}}
No Content
{{/each}}
我尝试了{{{each object}}
和{{{each array}}
,但这两种方法都会导致“无内容”
我做错什么了吗?你需要使用{{{{each[]}}
{{#each[]}
{{this.Title}}
{{this.CreateDate}}
{{else}
没有内容
{{/每个}}
这是我的小提琴