2011-04-18 15:36:46 +00:00
|
|
|
var <%= plural_object_name %>View = Backbone.View.extend({
|
|
|
|
template: JST['<%= plural_underscore_name %>/list'],
|
2011-04-15 19:32:04 +00:00
|
|
|
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());
|
2011-04-15 20:14:18 +00:00
|
|
|
return this;
|
2011-04-15 19:32:04 +00:00
|
|
|
},
|
|
|
|
addOne: function(model) {
|
2011-04-15 20:11:57 +00:00
|
|
|
var view = new <%= object_name %>View({model: model});
|
2011-04-15 19:32:04 +00:00
|
|
|
this.$('.list').append(view.render().el);
|
|
|
|
},
|
|
|
|
addAll: function() {
|
|
|
|
this.collection.each(this.addOne);
|
|
|
|
}
|
|
|
|
});
|