部分覆盖Backbone.sync

时间:2012-10-03 11:35:02

标签: javascript backbone.js

有没有办法部分覆盖Backbone.sync,比如仅createupdate,并让readdelete使用本机Backbone.sync?< / p>

1 个答案:

答案 0 :(得分: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;