Are there any events my models can bind to, to know their collection has been reset?
When I call:
collection.reset()
I want those removed models to be destroyed and in turn any views to know they are gone. What should I bind to here?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
@mu’s answer is correct, but you might also need to know that a model that is added to a collection has the
.collectionproperty, which points to the parent collection. So if you are instantiating your models manually, you can just do this:But if you’re instantiating your models via the collection, e.g. with
collection.fetch(), you need to bind to the collection in theinitialize()method of the model: