保存整个集合最佳实践? [英] Best practice for saving an entire collection?

查看:180
本文介绍了保存整个集合最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个集合,我已经修改了它的许多模型。什么是使用一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆