立即自动节省微风 [英] Immediate Auto Saving with breeze

查看:101
本文介绍了立即自动节省微风的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Knockout和breezejs实现一个表单,我希望在用户更改焦点时保存每个字段。因此,每次更改都意味着对服务器的一次保存调用问题是,如果用户在上一次保存呼叫完成时进行了一些更改,则当服务器响应时,第一次呼叫中未包含的更改将恢复为其原始值。

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.

这是我的经理的配置:

var manager = new breeze.EntityManager({
    serviceName : "/api/UserCentre/",
    saveOptions: new breeze.SaveOptions({allowConcurrentSaves: true})
});
manager.enableSaveQueuing(true);


推荐答案

删除 saveOptions 你会没事的。 SaveQueuing和 allowConcurrentSaves 是竞争方法。

Remove the saveOptions and you'll be fine. "SaveQueuing" and allowConcurrentSaves are competing approaches.

我强烈反对使用 allowConcurrentSaves ,因为它可能导致不稳定的数据库插入和更新。这就是默认为 false 的原因。这是一个我从未感到舒适使用的高级功能。

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是专为您的场景设计的插件。它作为单独的JS文件( breeze.savequeuing.js )作为样本的一部分提供。它将客户端应用程序保存请求排队,确保每个请求仅在前一个请求完成后发出。无论如何都不是万无一失的;他们是可以绊倒你的边缘条件。但这是我们发现的最好的方法,可以像你一样经常自动保存。

"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.

这篇关于立即自动节省微风的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆