How to save a collection of models in backbone.js?

I use the trunk in the project. I have a scenario when I added some of my models to the collection. Now I have an array of models in the collection. I use rest serivces to save. Now I want to make a mail call to the server to save this array of models. I know that there is a model transfer method to create a collection method, like

  this.collection.create (model) 
But this is the only model to save. I also tried applying the loop, but it does not work. Please help me.

Thanks in advance

+7
source share
1 answer

You need to use the function . add ()

this.collection.add(model); this.colleciton.add([model1, model2, ..., modeln]); 

Edit:

To save the models in the collection, you will need to write a function to iterate through them and save them individually.

StackOverflow has the answers to this question pretty well, for example:

How to save a whole collection in Backbone.js - Backbone.sync or jQuery.ajax?

Best practice for keeping the entire collection?

How to save a collection using backbone.js

+3
source

All Articles