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

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

问题描述

假设我有一个集合并且我对其许多模型进行了更改.使用单个 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天全站免登陆