How to save collection of models in backbone.js?

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

链接地址: http://www.djcxy.com/p/11510.html

上一篇: 图像处理:对象的旋转对齐

下一篇: 如何在backbone.js中保存模型集合?