将事件侦听器添加到转发器内的 Flex 组件

发布于 2024-12-09 06:30:42 字数 428 浏览 2 评论 0原文

我想为转发器内的每个组件添加一个事件侦听器,但不知道如何操作。这是我尝试过的一些代码:

<mx:Repeater id="rp" dataProvider="{dataProvider}" width="100%">
   <mx:Button id="attach" creationComplete="addListeners(attach[rp.currentIndex])"/>
</mx:Repeater>

这不起作用。在中继器完成之前不会调用creationComplete,而不是(如我预期的那样)在按钮创建完成时调用。我不知道如何实现这一点。

顺便说一句 - 我还尝试将creationComplete放在中继器的父组件上,但它只会在第一次渲染组件时被调用(中继器内的数据有时会发生变化),所以这不起作用。

I want to add an event listener to each component inside a repeater, but don't know how. Here's some code I have tried:

<mx:Repeater id="rp" dataProvider="{dataProvider}" width="100%">
   <mx:Button id="attach" creationComplete="addListeners(attach[rp.currentIndex])"/>
</mx:Repeater>

This doesn't work. creationComplete is not called until the repeater has finished instead of (as I expected) when the creation of the button is complete. I'm not sure how to accomplish this.

BTW - I also tried placing the creationComplete on the parent component to the repeater, but it would only be called the first time the component was rendered (the data inside the repeater sometimes changes) so that didn't work.

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

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

发布评论

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

评论(1

生死何惧 2024-12-16 06:30:42

如果您使用元数据中定义的事件,则只需添加 click="myClickHandler(event)" 即可。你也可以这样做:

<yourNS:YourComponent id="foo>
    <creationComplete>
        <fx:Script>
            (foo[yourRepeater.currentIndex] as EventDispatcher).addEventListener('the event', yourEventHandler);
        </fx:Script>
    </creationComplete>
</yourNS:YourComponent >

If you're using an Event defined in metadata, it can be as simple as adding click="myClickHandler(event)". You can also do something like this:

<yourNS:YourComponent id="foo>
    <creationComplete>
        <fx:Script>
            (foo[yourRepeater.currentIndex] as EventDispatcher).addEventListener('the event', yourEventHandler);
        </fx:Script>
    </creationComplete>
</yourNS:YourComponent >
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文