backbone-generator/templates/collection_view.js.erb

24 lines
614 B
Plaintext

var <%= object_name %>sView = Backbone.View.extend({
template: JST['<%= underscore_name %>s'],
initialize: function(collection) {
_.bindAll(this, 'render', 'addOne', 'addAll');
this.collection = collection;
this.collection.bind('refresh', this.addAll);
this.render();
this.collection.fetch()
},
render: function() {
$(this.el).html(this.template());
return this;
},
addOne: function(model) {
var view = new <%= object_name %>View({model: model});
this.$('.list').append(view.render().el);
},
addAll: function() {
this.collection.each(this.addOne);
}
});