I am using backbone in a project. I have a scenario where I have added my multiple models in a collection. Now i have array of models in the collection. I am using rest serivces in order to save. Now I want to make a post call to the server to save those array of models. I know there is a method to pass model to create method of collection like
this.collection.create(model)But it is for single model to save. I had also tried to apply loop but it doesn't seem to work. Please help me out.
Thanks in advance
You need to use the .add() function
this.collection.add(model);
this.colleciton.add([model1, model2, ..., modeln]);
Edit:
To save the models that are in the collection, you will need to write a function to iterate through them and save them all individually.
There are StackOverflow questions the answer this pretty well, for example:
"How" to save an entire collection in Backbone.js - Backbone.sync or jQuery.ajax?
Best practice for saving an entire collection?
How to save a Collection with backbone.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With