How can you watch for changes on a single attribute of a model?

Report
Question
12 views

Please explain why do you think this question should be reported?

Report Cancel

Model objects fire the “change” event whenever some data changes within the model. However, the object fires another event with a name specific to the attribute that has changed: “change:[attribute]”. For example:

var Fruit = Backbone.Model.extend({})
var fruit = new Fruit({
    weight: 3.25
})
fruit.on(‘change:weight, function() {
    // Event “change:weight” will fire whenever the weight attribute of fruit changes.
})

Please follow and like us:

About the Author