Backbone save without set on callback

Asked By: Anonymous

I have a drag&drop functionality in my web app. As the user releases the mouse after a drag&drop, the position of the object is saved to the server using Backbone’s save() method on the model. When the server responds, it triggers a set() on the model with the returned properties. However, in the time the server was processing the request, the user might already have again dragged the object to a different position. This causes problems as the response from the server will now override the settings of the object in the browser.

Is there a way to prevent Backbone from doing the set() after it gets the response from the server after the save()?


Solution

Answered By: Anonymous

I now use the following solution:

Override the default parse method of a model:

Backbone.Model.prototype.parse = function(resp, options) {
    if(options.parse)
        return resp;
};

Now, you can use the save method with the property ‘parse’ set to false to prevent the ajax response to override your current values:

MyModel.save({}, { parse: false });

Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno