Answer the question
In order to leave comments, you need to log in
Why is there no way to save a collection in backbone.js?
I'm wondering why they didn't make it possible to save, update or delete an entire collection?
Consider, for example, this case: there is a collection of photos on a page. Each photo has a property with an index by which you can sort the output of photos for the client. When the user changes this property, all indexes on all photos in the collection must be updated. After this is done, all this data must be sent to the server for storage. In this case, we can only iterate through each model and call save(), which means that many http requests will be made (one request for each photo), when it would be possible to do just one if it were possible to save|update the collection.
Answer the question
In order to leave comments, you need to log in
Because it's not a REST way.
In general, with such strange questions, you are here .
Because the backbone was written to be as flexible as possible. You are expected to extend save for collections yourself. But in practice, there is no way to write on a "bare bckbone", as this is not the only problem you will encounter. You need to choose a set of ready-made extensions for your application.
Thanks to everyone who gave their answer.
I came to the conclusion that it is universally impossible to save a collection: imagine that you have a collection that has been changed - new models have been added, existing models have been changed, and some models have been deleted altogether. Thus, it is impossible to form one http request to the server by any one method (get, post, put or delete), because each must be used according to the rules of REST.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question