Frage

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.

War es hilfreich?

Lösung

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`
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top