24 lines
619 B
Plaintext
24 lines
619 B
Plaintext
var <%= object_name %>sView = Backbone.View.extend({
|
|
template: JST['<%= underscore_name %>s/list'],
|
|
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);
|
|
}
|
|
});
|