-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Destroying all models from a collection #139
Comments
I ended up extending both Model and Collection with methods for those. Here those are: |
So, there are two things here. The first is destroying all the models in a collection on both the client and the server, and the second is simply removing all the models from a collection, client-side. The reason why backbone doesn't have the former built-in is because it's not standard in basic REST, and we won't want to encourage folks to be submitting 100 individual HTTP requests, one to destroy each item. You should have a special endpoint to perform a bulk destroy, and then empty your collection client-side, which can be done like so:
|
What happens if you have code that watches a particular model? It would never know it got removed. |
I have been searching for a long time but I came across this and was wondering if you could send me your deleteAll method for a backbone collection. Here is my issue. I hit an api to get a list of items and I store them in a collection. I then want to completely remove all items in the collection and refresh them with a nw list. I can do that locally but when I call fetch on the collection all the items come back again as they are not removed from the server. I can also do the whole removing one item at a time from the server but that can take 15 seconds to finish if I have about 200 items. Preferably I want to both call refresh locally and one call to remove all items on the server to speed up the removal process. Any help would be appreciated. |
Not so obviously 'collection.invoke("destroy")' does not work. How would one empty a collection?
The text was updated successfully, but these errors were encountered: