Skip to content

Instantly share code, notes, and snippets.

@fatboab
Created May 31, 2012 10:08
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 fatboab/2842406 to your computer and use it in GitHub Desktop.
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...
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)
});
}
// ...
});
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