Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created May 9, 2012 14:07
Show Gist options
  • Save JakubOboza/2644726 to your computer and use it in GitHub Desktop.
Save JakubOboza/2644726 to your computer and use it in GitHub Desktop.
$(document).ready(function(){
App.Views.EntriesView = Backbone.View.extend({
el: $("#entries"),
initialize: function(){
_.bindAll(this, 'render');
this.collection = new App.Collections.EntriesList();
this.collection.bind('add', this.appendItem);
this.render();
},
render: function(){
var self = this;
_(this.collection.models).each(function(item){
// in case collection is not empty
self.appendItem(item);
}, this);
return this;
},
appendItem: function(item){
var entryView = new App.Views.EntryView({
model: item
});
$(this.el).append(entryView.render().el);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment