Asked By: Anonymous
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
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
Answered By: Anonymous
You need to use the .add() function
this.collection.add(model); this.colleciton.add([model1, model2, ..., modeln]);
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: