保存整个集合最佳实践? [英] Best practice for saving an entire collection?
问题描述
说我有一个集合,我已经修改了它的许多模型。什么是使用一个HTTP请求保存所有的变化的最佳方式?
Say that I have a Collection and I've made changes to many of its Models. What's the best way to save all of the changes using a single HTTP request?
推荐答案
通常REST后端处理单实例创建/更新。您需要更改接受对象的数组。
Usually REST backends handle single instance creation/update. You would need to change that to accept an array of objects.
这表示,在客户端,你需要直接去Backbone.sync功能
That said, on the client side, you would need to go directly to the Backbone.sync function
Backbone.sync = function(method, model, options)
在这种情况下,你的模式应该是模型的数组。该方法应该是创造或保存和选项采用相同类型的选项为jQuery的AJAX调用(错误,成功等)
In this case your model should be an array of model. The method should be "create" or "save" and the options take the same type of options as a jQuery ajax call (error, success, etc.)
这篇关于保存整个集合最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!