Create a gist now

Instantly share code, notes, and snippets.

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