Created
February 1, 2013 16:35
-
-
Save sap1ens/4692429 to your computer and use it in GitHub Desktop.
Adding Backbone.js custom REST method
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
var MyModel = Backbone.Model.extend({ | |
someMethod: function(opts) { | |
var url = this.url() + '/someMethod', | |
// note that these are just $.ajax() options | |
options = { | |
url: url, | |
type: 'POST' | |
}; | |
// add any additional options, e.g. a "success" callback or data | |
_.extend(options, opts); | |
return (this.sync || Backbone.sync).call(this, null, this, options); | |
} | |
}); |
You can call this.sync
directly http://backbonejs.org/docs/backbone.html#section-62
options = _.extend(options, opts);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
perfect, thanks!