I was asked to remove couple of attributes from a backbone model (which was optional) where they exists. My first intent was to place something like a before_save
callback on a model. But i didn't find any information googling.
is it possible to do that on a backbone side?
Just override default Model.save
and add your callback to it.
var MyModel = Backbone.Model.extend({
save: function (key, val, options) {
this.beforeSave(key, val, options);
return Backbone.Model.prototype.save.call(this, key, val, options);
},
beforeSave: function (key, val, options) {
}
})
If you want only to remove particular attributes from being sent to the server than you may override Model.toJSON
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With