backbone-generator/templates/view.js.erb

22 lines
535 B
Plaintext

var <%= object_name %>View = Backbone.View.extend({
events: {
'click button.save': 'save'
},
attributeFields: [],
template: JST['<%= underscore_name %>s/view'],
initialize: function() {
_.bindAll(this, 'render', 'save');
this.model.bind('change', this.render);
},
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
this.$('button.save').text(this.model.isNew() ? 'Create' : 'Update');
return this;
},
save: function() {
this.model.save(this.attributes());
}
});