Created
October 18, 2013 06:53
-
-
Save mallim/7037481 to your computer and use it in GitHub Desktop.
Example showing how to override Backbone Model sync method (specific to a model)
This file contains hidden or 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
var MyModelOverrideLocal = Backbone.Model.extend({ | |
sync: function (method, model, options) { | |
if ( method === 'delete' ) { | |
if ( options.data ) { | |
// properly formats data for back-end to parse | |
options.data = JSON.stringify(options.data); | |
} | |
// transform all delete requests to application/json | |
options.contentType = 'applicaton/json'; | |
} | |
if (method === 'read') { | |
// Do something | |
} | |
if( method === 'create'){ | |
// Do something | |
} | |
if( method === 'update'){ | |
// Do something | |
} | |
Backbone.apply(this, [method, model, options]); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment