Best practice for saving an entire collection?

后端 未结 4 1241
生来不讨喜
生来不讨喜 2020-12-08 06:55

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?

4条回答
  •  遥遥无期
    2020-12-08 07:29

    Usually REST backends handle single instance creation/update. You would need to change that to accept an array of objects.

    That said, on the client side, you would need to go directly to the Backbone.sync function

    Backbone.sync = function(method, model, options)
    

    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.)

提交回复
热议问题