Flex json 自动更新数据网格

发布于 2024-11-01 18:44:01 字数 311 浏览 1 评论 0原文

我正在使用 Flex 4。有 PHP 后端和 mysql 数据库,一张表由多行组成。

我从结果事件中获取原始数据并使用 JSON 对其进行解码。然后,我将数据转储到 ArrayCollection 中,用作数据网格的数据提供程序。

我的问题是我如何知道何时有人将新行插入 mysql 表中,以便我可以自动刷新我的 ArrayCollection,从而一次无缝更新我的数据网格一个元素?现在,这只是一次性调用,连接已关闭。如果有人在数据库中插入新行,我的程序将无法识别,除非我重新启动它。我想在 mysql 数据库中插入一个新行时自动更新 AC。有没有办法让我“聆听”这种变化?

I'm using Flex 4. Have PHP backend and mysql database with one table consisting of multiple rows.

I take the raw data from the result event and decode it using JSON. I then dump the data into an ArrayCollection that I use as my datagrid's data provider.

My question is how can I tell when someone inserts a new row into the mysql table so that I can automatically refresh my ArrayCollection, thus seamlessly updating my datagrid one element at a time? Right now, it's just a one time call and the connection is closed. If someone inserts a new row into the database my program doesn't recognize, unless I restart it. I'd like to auto-update the AC whenever a single new row is inserted into the mysql database. Is there a way I can "listen" for this change?

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

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

发布评论

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

评论(2

从此见与不见 2024-11-08 18:44:01

啊,您偶然发现了网络领域的一个古老问题:轮询还是推送?

轮询意味着您每隔几秒或几分钟对服务器执行一次 ping 操作,以检查是否有任何数据发生更改。如果有,您的服务器会向您发送新的更改数据,这些数据会在您的前端上适当更新。关于如何解释哪些数据需要更新的“协议”完全取决于您,因为没有真正的标准(因为数据本身可能因系统而异)。如今,轮询仍在许多不需要关键“实时”信息的系统中使用,并且由于它不需要一致的连接,因此它特别适合移动等不稳定的互联网。另外,一切都是 HTTP 请求,因此没有企业防火墙可以阻止它。

推送意味着前端和后端之间有持续的连接,通常通过 RTMPT(用于绕过企业防火墙的 HTTP UDP 协议,但不是 100%)。如果您需要快速向您提供实时数据(例如财务数据),那么这非常有用。但是,用户需要一致的互联网连接,并且您需要拥有能够处理连接量和会话管理的服务器。通常,大多数人最终会使用 Java,因为有许多库可以处理推送(BlazeDS、GRaniteDS、Livecycle、Wowza 等)。

由于您使用的是 PHP,因此您可能需要使用轮询作为解决方案,但需要自己实现。我确信有图书馆可以帮助你。

Ah, you've stumbled upon the age old question of the web realm: Polling or Pushing?

Polling means that you ping the server every few seconds or minutes to check if there's any data that has changed. If there is, your server sends you the new changed data which up update appropriately on your front-end. The 'protocol' on how to interpret which piece of data needs to be updated is totally up to you since there's no real standard (since data in itself can be very different from system to system). Polling is still in use today in many systems that do not need crucial 'live' information and since it doesn't need a consistent connection, it's particularly good for iffy internet like mobile. Plus, everything is an HTTP request, so there's no enterprise firewall that can block it.

Pushing means that you have a constant connection between your front end and back end which normally goes over RTMPT (HTTP UDP protocol to circumvent enterprise firewalls, but not 100%). It's great if you need real time data (like say financial data) to be delivered to you quickly. However, the user needs a consistent internet connection and you need to have a server capable of dealing with the amount of connections and sessions management. Normally, most people end up using Java since there are many libraries to handle pushing (BlazeDS, GRaniteDS, Livecycle, Wowza, etc).

Since you're using PHP, you'll probably need to use polling as your solution, but need to implement it yourself. I'm sure there are libraries out there to help you out though.

短暂陪伴 2024-11-08 18:44:01

不,没有自动方法可以做到这一点。但您可以定期“ping”您的服务器并请求新行。用来

setInterval(myFunctionName, timeToWaitBetweenEachCallInMilliseconds);

做那件事。

No, there is no automatic way to do that. But you can regularly 'ping' your server and ask for new rows. Use

setInterval(myFunctionName, timeToWaitBetweenEachCallInMilliseconds);

to do that.

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