在保存之前如何检查表单中的哪些值已更改?

发布于 2024-11-26 20:55:00 字数 303 浏览 0 评论 0原文

情况是这样的。我们有一个包含大量字段的表单(超过 30 个字段分布在多个选项卡上),我想要做的是在保存之前找到哪些值已更改,并对性能影响最小。现在发生的情况是,为了编辑,从多个数据库查询单个记录。这些值作为值对象传递到客户端。目前,它们尚未绑定到表单中的任何字段。

我最初的想法是为每个字段设置一个布尔标志,以便在每次更改任何字段时设置 true 或 false。保存时,程序将运行标志列表以查看哪些字段已更改。这对我来说似乎有点笨重,所以我想也许可以在服务器端完成。但是我不想一一检查每个字段以查看哪些字段与数据库记录不匹配。

关于在这里做什么有什么想法吗?

The situation is like this. We have a form with a large number of fields (over 30 spread over several tabs) and what I want to do is find which values have changed before saving with minimum impact on performance. What happens right now is, for editing, single records are queried from several databases. The values are passed over to the client side as value objects. At the moment they are not bound to any fields in the form.

My initial idea was to have a boolean flag for each field to set true or false each time any of the fields were changed. At the time of saving the program would run through the list of flags to see which fields have changed. This seems more than a bit clunky to me so I was thinking maybe it could be done on the server side. But then I don't want to go through each field one by one checking to see which ones don't match the db records.

Any ideas on what to do here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

残疾 2024-12-03 20:55:00

对于许多 Flex 应用程序来说,这是一个非常常见的问题。因为这种情况经常发生,所以有许多数据管理的商业实施。查询存储在实体中,并且这些实体绑定到客户端的表单。每当更新字段时,它都会自动执行步骤以将更改保存到数据库并在请求时进行回滚。

Adobe LCDS 数据管理 - 如果您正在处理 Java 环境
WebOrb - 如果您正在处理 .net、php、java、rails 环境

当然您可以重新发明轮子并推出自己的,在每个字段上设置 PropertyChangeEvent 侦听器。当更改被分派时,监听它们并为每一个更改编写处理程序。

This is a very common problem for a lot of Flex applications. Because it happens so often there are a number of commercial implementations for Data Management. Queries are stored into entities and those entities are bound to a form on the client side. Whenever a field is updated, it will automatically perform the steps to persist the changes to the db and do rollbacks when requested.

Adobe LCDS Data Management - If you are dealing with a Java environment
WebOrb - If you are dealing with a .net, php, java, rails environment

Of course you can re-invent the wheel and roll out your own, set up PropertyChangeEvent listeners on each field. When the changes are dispatched, listen for them and write handlers for each one.

风筝在阴天搁浅。 2024-12-03 20:55:00

这听起来和我们正在为客户做的一个项目一模一样。

我们所做的就是在值对象返回 UI 后对其进行欺骗。然后,当调用更新服务时,我发送原始对象和新对象。在服务中,我在服务器上进行逐字段比较,以确定应将哪些值发送到数据库。

如果您需要根据每个字段/属性是否更改来有条件地更新它;那么我没有找到避免检查每个字段/属性的方法。即使您实现了布尔思想并在发生任何变化时交换 UI 中的标志;在创建查询时,您仍然需要检查这些布尔值以确定应该更新或不更新哪些内容。

在我的情况下,会查询三个不同的数据库来创建发送回 UI 的值对象。字段更新保存在其中一个数据库中,并在进行选择时给出第一优先顺序。因此,我们在存储过程中进行了显式的逐字段比较。

如果您不需要逐字段比较,而是需要“逐记录”比较;那么布尔方法让您知道记录/值对象已更改将节省您一些时间和编码。

This sounds exactly like what we're doing with one of the projects I'm working on for a client.

What we do is dupe the value objects once they back to the UI. Then when calling the update service, I send both the original object and the new object. In the service, I do a field by field compare on the server to determine what values should sent to the database.

If you need to update every field/property conditionally based on whether or not it changed; then I don't see a way to avoid the check with every field/property. Even if you implement your Boolean idea and swap the flag in the UI whenever anything changes; you're still going to have to check those Boolean values when creating your query to determine what should be updated or not.

In my situation, three different databases are queried to create the value object that gets sent back to the UI. Field updates are saved in one of those database and given first order of preference when doing the select. So, wee have an explicit field by field comparison happening inside a stored procedure.

If you don't need field by field comparisons, but rather a "record by record" comparisons; then the Boolean approach to let you know the record/Value Object had changed is going to save you some time and coding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文