问题
I am implementing a form using Knockout and breezejs, I want to save each field when the user change the focus. So each change implies one save call to the server. The problem is that if the user does some changes while the previous save call is beeing done, the changes which weren't included in the first call, are restored to their original values when the server responds.
This is the configuration of my manager:
var manager = new breeze.EntityManager({
serviceName : "/api/UserCentre/",
saveOptions: new breeze.SaveOptions({allowConcurrentSaves: true})
});
manager.enableSaveQueuing(true);
回答1:
Remove the saveOptions
and you'll be fine. "SaveQueuing" and allowConcurrentSaves
are competing approaches.
I strongly discourage the use of allowConcurrentSaves
as it can lead to unstable database inserts and updates. That's why it is defaults to false
. It's really an advanced feature that I've never felt comfortable using.
"SaveQueuing" is a plug-in designed for your scenario. It ships as a separate JS file (breeze.savequeuing.js) as part of the samples. It queues client application save requests, ensuring that each request is issued only after the prior one completes. It's not foolproof by any means; their are edge conditions that can trip you. But it's the best approach we've discovered for auto-saving frequently as you are doing.
来源:https://stackoverflow.com/questions/16042574/immediate-auto-saving-with-breeze