Assume a Backbone model with the following attributes: - subtotal - discount - total
Whenever a change is made to discount, the total needs to be updated and I'd like the model to care of this.
I have tried binding an update method (defined in the model) to the model's change event (in the model's initialize method) so that with each change event, the model would update the total attribute, but this does not seem to work.
var Cost = Backbone.Model.extend({
initialize : function() {
this.bind('change', this.update);
},
update : function() {
// UPDATE LOGIC
}
});
What is the best approach to have the model fire a method (of its own) when it triggers a change event?