Does Backbone.js set callback before saving?

I was asked to remove a pair of attributes from the base model (which was optional) where they exist. My first intention was to put something like a before_save on the model. But I did not find any search information. can this be done on the trunk side?

+6
source share
1 answer

Just override the default value of Model.save and add a 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 only want to remove certain attributes sent to the server, than you can override the Model.toJSON method.

+13
source

Source: https://habr.com/ru/post/944694/


All Articles