Domanda

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.

È stato utile?

Soluzione

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`
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top