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.

有帮助吗?

解决方案

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`
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top