I have a collection of Backbone models, each having several attributes: _id, code, title, date and selected.
I want the "selected" attribute value to be true only in one of the collection models at a time. When I set a model "selected", all other models in the collection should be set to {selected:false}
.
I'm thinking about two different solutions:
1) from "inside" the model: I can listen to the change of selected attribute, loop all the parent collection items, and set selected:false if _id != id of this
2) from "outside", loop over collection models, set all to selected:false, except the one who matches id I want to be selected:true.
Is there a better practice to do that? Thank you