在 Flex 4 中访问父应用程序的状态

发布于 2024-10-07 07:51:14 字数 99 浏览 7 评论 0原文

我有几个自定义组件,所有这些组件都包含在父应用程序中。

当我尝试从自定义组件更改状态时,收到一条错误消息“未定义状态:状态名称”。如何从自定义组件中更改应用程序的状态?

I have several custom components all of which are included in the parent application.

When I try to change state from a custom component, I get an error saying "undefined state: state name". How do I change the state of the application from within a custom component ?

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

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

发布评论

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

评论(2

从﹋此江山别 2024-10-14 07:51:14

为了防止您的自定义组件与您的应用程序绑定,我建议让该组件调度父应用程序侦听的自定义事件。父应用程序在收到来自组件的事件后将更改其自己的状态。希望有帮助。

To keep your custom component from being tied to your application I would recommend having the component dispatch a custom event that the parent application listens for. The parent application would then change its own state after receiving the event from the component. Hope that helps.

浪推晚风 2024-10-14 07:51:14

简单但错误的方法:

(parent as __application-class__).state = "__state-name__"

用适当的名称替换带下划线的术语。但正如韦德指出的那样,这是一种笨拙且脆弱的方法。如果您的应用程序很小并且不会被其他开发人员看到,那也没关系。

正确的方法是将主应用程序设置为更改其自身状态,以响应某些条件或输入,例如另一个组件触发的事件。

The simple but wrong way:

(parent as __application-class__).state = "__state-name__"

replacing the terms with underlines with their appropriate names. but as wade pointed out, it's a clumsy, brittle way to do it. If your application is small and not going to be seen by other developers though this is fine.

The right way of doing this would be setting up your main application to change its own state in response to some condition or input such as an event fired by another component.

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