Question

When I am listening for a change event for a boolean attribute of a model in the collection, how do I handle the event to toggle to turn the bool off on all the other models in the collection.

Was it helpful?

Solution

Try this :

// in your model
yourModel.on('change:yourBooleanAttribute', yourCollection.setAllButCurrent);

// and in your collection
setAllButCurrent: function(changedModel, value, options) {
    // here you can iterate through `this.models` and for each model 
    // if it's `id` differ from changedModel id, change it's `yourBooleanAttribute`
    // to the opposite value of `value`
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top