Reputation: 3011
I have got a Json from the collections by calling the APIs.
{
"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"
}
}]
}
This is the Views:
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;
}
});
Now how do i get these entries in Template?
<h1>Stream</h1>
<%= entries["posts"] %>
entries["posts"] doesn't display the posts?
Upvotes: 0
Views: 144
Reputation: 2841
You should cycle the array and you can use javascript code inside your template using the <% %> tags.
An example could be:
<ul>
<% _.each(entries.posts,function(post){ %>
<li><%= post.actor.displayName %><li>
<% }); %>
</ul>
Upvotes: 1