有没有办法部分覆盖Backbone.sync,比如仅create
和update
,并让read
和delete
使用本机Backbone.sync?< / p>
答案 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;