Skip to content

Instantly share code, notes, and snippets.

@SeonghoonKim
Created September 5, 2012 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeonghoonKim/3634343 to your computer and use it in GitHub Desktop.
Save SeonghoonKim/3634343 to your computer and use it in GitHub Desktop.
Backbone.js Synchronization URL 설정
// 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