Created
May 31, 2012 10:08
-
-
Save fatboab/2842406 to your computer and use it in GitHub Desktop.
I always forget to bind the Backbone save success and error functions to this...
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
Backbone.View.extend({ | |
events: { | |
'click a.enable': 'enableHandler', | |
'click a.disable': 'disableHandler' | |
}, | |
initialize: function() { | |
this.model = new Model(); | |
this.model.bind('change', this.render, this); | |
} | |
// ... | |
enableHandler: function(e) { | |
e.preventDefault(); | |
this.model.save({ | |
enabled: true | |
}, { | |
wait: true, | |
success: _.bind(function() { | |
this.$('a.enable').hide(); | |
this.$('a.disable').show(); | |
}, this), | |
error: _.bind(function() { | |
// ... | |
}, this) | |
}); | |
} | |
// ... | |
}); |
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
Backbone.View.extend({ | |
events: { | |
'click a.enable': 'enableHandler', | |
'click a.disable': 'disableHandler' | |
}, | |
initialize: function() { | |
this.model = new Model(); | |
this.model.bind('change', this.render, this); | |
} | |
// ... | |
enableHandler: function(e) { | |
e.preventDefault(); | |
this.model.save({ | |
enabled: true | |
}, { | |
wait: true, | |
success: function() { | |
this.$('a.enable').hide(); | |
this.$('a.disable').show(); | |
}, | |
error: function() { | |
// ... | |
} | |
}); | |
} | |
// ... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment