“How” to save an entire collection in Backbone.js - Backbone.sync or jQuery.ajax?

前端 未结 11 1279
醉梦人生
醉梦人生 2020-11-28 19:45

I am well aware it can be done and I\'ve looked at quite a few places (including: Best practice for saving an entire collection?). But I\'m still not clear \"exactly how\"

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 20:17

    A very simple...

    Backbone.Collection.prototype.save = function (options) {
        Backbone.sync("create", this, options);
    };
    

    ...will give your collections a save method. Bear in mind this will always post all the collection's models to the server regardless of what has changed. options are just normal jQuery ajax options.

提交回复
热议问题