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

前端 未结 11 1316
醉梦人生
醉梦人生 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:29

    I would try something like:

    var CollectionSync = function(method, model, [options]) {
        // do similar things to Backbone.sync
    }
    
    var MyCollection = Backbone.Collection.extend({
        sync: CollectionSync,
        model: MyModel,
        getChanged: function() {
            // return a list of models that have changed by checking hasChanged()
        },
        save: function(attributes, options) {
            // do similar things as Model.save
        }
    });
    

    ( https://stackoverflow.com/a/11085198/137067 )

提交回复
热议问题