You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got a sub-collection that filters on an attribute value.
When I iterate on this sub-collection to modify attribute's value (the modification should remove the model from the collection), only half of the models are concerned by the modification.
I reproduced the bug in http://jsbin.com/elisor/3/edit.
I'm not sure it's a bug, since iterating on a collection that modifies itself is maybe not a feature, but I would like to know the workaround in this case.
However, Backbone handles well the case of removing of model while iterating on a collection. EDIT: backbone does not support that (http://jsbin.com/elisor/2/edit)
The text was updated successfully, but these errors were encountered:
It's the each method that is the problem. Iterating over the collection and removing things mid-way will cause issues. In the past I've manually looped over the models in the collection or cloned it like you had there.
You could also silence those changes and call the refresh method on the subset so it will update.
Not the prettiest but you'll always have issues with things like this with the each method. I'll have a think about it. Maybe there is a better solution.
I've got a sub-collection that filters on an attribute value.
When I iterate on this sub-collection to modify attribute's value (the modification should remove the model from the collection), only half of the models are concerned by the modification.
I reproduced the bug in http://jsbin.com/elisor/3/edit.
I'm not sure it's a bug, since iterating on a collection that modifies itself is maybe not a feature, but I would like to know the workaround in this case.
However, Backbone handles well the case of removing of model while iterating on a collection. EDIT: backbone does not support that (http://jsbin.com/elisor/2/edit)
The text was updated successfully, but these errors were encountered: