Created
September 5, 2012 09:58
-
-
Save SeonghoonKim/3634343 to your computer and use it in GitHub Desktop.
Backbone.js Synchronization URL 설정
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When urlRoot or url does not meet URL requirement, override sync method | |
var MyModel = Backbone.Model.extend({ | |
sync : function(method, model, options) { | |
options || (options = {}); | |
if (method === 'read') { | |
options.url = '/path/to/read/api?id=' + encodeURIComponent(this.id); | |
} else if (method === 'create') { | |
options.url = '/path/to/create/api'; | |
} else if (method === 'update') { | |
options.url = '/path/to/update/api?id=' + encodeURIComponent(this.id); | |
} else if (method === 'delete' { | |
options.url = '/path/to/delete/api?id=' + encodeURIComponent(this.id); | |
} else { | |
this.trigger('error', this, 'unknown method: ' + method, options); | |
return false; | |
} | |
return Backbone.sync.call(this, method, this, options); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment