我通过调用API从集合中获得了Json。
{
"next_page_link": null,
"prev_page_link": null,
"posts": [
{
"id": 1,
"public": true,
"actor": {
"displayName": "Srikanth Jeeva",
"id": "28"
}
},
{
"id": 2,
"public": true,
"actor": {
"displayName": "Srikanth jeeva",
"id": "21"
}
}]
}
这是观点:
Raffler.Views.StreamsIndex = Backbone.View.extend({
template: JST['streams/index'],
initialize: function(){
this.collection.on('reset',this.render, this);
},
render: function(){
$(this.el).html(this.template({entries: this.collection}));
return this;
}
});
现在我如何在模板中获取这些条目?
<h1>Stream</h1>
<%= entries["posts"] %>
条目[“帖子”]不显示帖子?
答案 0 :(得分:1)
您应该循环数组,并且可以使用&lt; %%&gt;在模板中使用javascript代码。标签
一个例子可能是:
<ul>
<% _.each(entries.posts,function(post){ %>
<li><%= post.actor.displayName %><li>
<% }); %>
</ul>