Skip to content Skip to sidebar Skip to footer

Dependent Attributes In Backbone.js Model

If either of two values - a or b - change in my model, two of the listening views need to calculate a third value c. //Pseudo mainModel a : 2000 b : 3000 view1 helper.cal

Solution 1:

You can add a binding on the model to its own change event on the initialize call.

initialize: function() {
  this.bind("change", this.calculateC);
},

calculateC: function() {
  this.c = //fill in the blanks
}    

More specifically, you can bind only on the attributes you need.

this.bind("change:a", this.calculateC);
  this.bind("change:b", this.calculateC);

Post a Comment for "Dependent Attributes In Backbone.js Model"