Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two ways to solve this:</p> <ul> <li>Inheriting Backbone Model</li> </ul> <p>You could create your own custom model which inherits from Backbone Model. In it you could override the save method. <a href="http://documentcloud.github.com/backbone/#Model-extend" rel="nofollow">Read Backbone docs on how to extend their model</a></p> <p>In your custom save method, you will call the save method of super, check the responseText, if it's success then you'll call the success callback. (please do read backbone docs on how to call a method of your parent model in Javascript)</p> <ul> <li>Override Backbone.Sync</li> </ul> <p>Backbone has a Sync module which basically by default makes all ajax requests, parses the response and then calls the success/error callbacks you specified when calling save on your model. It's pretty simple. <a href="http://backbonejs.org/#Sync" rel="nofollow">Take a look at this doc</a> . Again you could override this, do exactly what Backbone is doing by default but only call the success/error callbacks based on responseText you received.</p> <p>UPDATE: Sample Code (warning code not tested)</p> <pre><code>//Over ride Backbone async defaultSync = Backbone.Sync // Save the original Sync method. We'll be needing that. Backbone.Sync = function(method, model, options) { success = options.success error = options.error options.success = function(model, data, options) { if (/% all your custom checks are true */) { success (model, data, options); } else { error(model,data,options); } } return defaultSync(method, model, options); } </code></pre> <p>Please make sure with this strategy the Sync method will be overriden for ALL your Backbone sync. If you don't want that then use Model#save override.</p> <p>Take a look at <a href="https://github.com/neebz/backbone-parse/blob/master/backbone-parse.js" rel="nofollow">this code</a> where I am overriding Backbone.Sync to make it work with Parse.com API.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload