Reputation: 5912
I've been checking the docs of Backbone and Underscore for a "proper" way to extract a model (remove the value and have it returned) from a collection. I know I can do this through direct access via the "models" array attribute and the splice method, but is that stepping around some built-in way I'm overlooking?
Upvotes: 0
Views: 636
Reputation: 57482
It is critical that you use the built-in "remove" method on the collection. Remove does the following:
If you manipulate the models inside the collection directly, none of the things above will happen.
More info on remove: http://documentcloud.github.com/backbone/#Collection-remove
Upvotes: 3
Reputation: 13542
From your comment:
I'm looking to actually remove the model at say index 5 and have that value returned.
Try this:
// given: myCollection is a Backbone collection
var item = myCollection.at(5);
myCollection.remove(item);
// ... now, do whatever else with `item`...
Upvotes: 1