2

有什么方法可以部分覆盖 Backbone.sync,比如说,只有createand update,离开readdelete使用本机 Backbone.sync?

4

1 回答 1

4

就那么简单:

// retain original sync with new name
Backbone.ajaxSync = Backbone.sync;

Backbone.customSync = function(method, model, option) {
    // Fallback for old sync method
    if (method == 'read' || method == 'delete') return Backbone.ajaxSync(method, model, option);

    // your custom code for other methods
    console.log('Custom sync for ' + method);
}

Backbone.sync = Backbone.customSync;
于 2012-10-03T12:39:16.327 回答