简体   繁体   中英

Backbone.model.save sending the whole backbone.model in request body

when i backbone.Model.save() , it sends the whole model data (each and every property even when it has not been modified) in the body of the request.

i want to send in the body only properties of the model, that has been modified.

I am doing :

here.model.save( 
                  {field:params.value},
                  { patch: true,
                    error: function() {
                      d.reject('Server Error..!');
                    },
                    success: function() {
                      d.resolve();
                    }
                  }
                );

but patch:true doesn't work.

what is the error? and how to resolve?

patch works only for already created models. In case if your model is new it wouldn't work.

How to fix it:

var model = new Backbone.Model();
var attributesToSave = {};
model.save(null, {attrs:attributesToSave});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM