backbone-generator/templates/collection_view.js.erb

29 lines
673 B
Plaintext
Raw Normal View History

var <%= plural_object_name %>View = Backbone.View.extend({
2011-05-03 19:43:19 +00:00
events: {
'click button.new': 'addNew'
},
template: JST['<%= plural_underscore_name %>/list'],
2011-05-03 19:43:19 +00:00
initialize: function() {
_.bindAll(this, 'render', 'addOne', 'addAll', 'new');
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);
2011-05-03 19:43:19 +00:00
},
addNew: function() {
}
});