Is it possible to listen for a change in a model in a collection if a specific field is changed to a specific value?
I know that something like 'change:fieldName' exists, I'm looking for something like 'changeTo: fieldName = true'
There's not a "shortcut" way of doing so. You have to listen to the normal change event, and in your listener, see if the value has changed to something interesting for you. Then, propagate the event, fire a new one, or do stuff.
Backbone.Collection.extend({
initialize: function() {
this.on('change:property', this.onChange);
},
onChange: function(e) {
// sorry for pseudo-code, can't remember syntax by heart, will edit
if (e.newValue == true)
myLogic();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With