在 Flex 中的组件初始化期间设置变量

发布于 2024-09-29 04:18:25 字数 343 浏览 3 评论 0原文

我正在加载一个组件,该组件进行 HTTPService 调用以获取数据,然后使用这些数据设置组件中的某些变量。我在 init() 函数中进行 HTTPService 调用(用于初始化事件),然后根据 HTTPService 结果处理程序中收到的数据设置变量。然而,在初始化阶段和创建完成阶段,变量仍然为空。如果我尝试读取creationComp()函数中的变量(对于creationComplete事件),这些变量仍然为空。这是正确的吗?

我想我不太了解 Flex 初始化周期。这些变量何时实际设置并可供使用?我需要在组件加载后自动操作这些变量。在creationComplete之后是否有一个合适的事件或其他方法来解决这个问题?我正在使用 Flex 3。

I am loading a component which makes a HTTPService call to get data that will then be used to set certain variables in the component. I make the HTTPService call in an init() function (for the initialization event) and then set the variables according to the data received in the HTTPService result handler. However, the variables are still null at both the initialize stage and at the creationComplete stage. If I try and read the variables in a creationComp() function (for the creationComplete event), those variables are still null. Is this correct?

I guess I don't understand the flex initialization cycle very well. When are those variables actually set and available to be used? I need to manipulate those variables automatically after the component loads. Is there an event that comes after creationComplete that is appropriate or some other way to approach this? I am using Flex 3.

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

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

发布评论

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

评论(2

终陌 2024-10-06 04:18:25

您对 Flex 组件生命周期的理解是正确的;在创建完成之前初始化事件触发。

然而,HTTPService 调用是一个单独的异步操作。不保证在creationComplete 事件触发时调用结果处理程序。您应该在结果处理程序中对变量进行操作。

Your understanding of the Flex component lifecycle is correct; initialize event fires before creationComplete.

However, an HTTPService call is a separate asynchronous operation. The result handler is not guaranteed to be called by the time the creationComplete event fires. You should do the manipulation of the variables in the result handler instead.

安稳善良 2024-10-06 04:18:25

您应该考虑在 HTTPService 返回之前阻止从组件分派creationComplete 事件,然后自己手动分派该事件。

这会解决你的时间问题。

You should think about preventing the creationComplete event being dispatched from your component until the HTTPService has returned, then manually dispatch the event yourself.

That would sort out your timing issues.

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