将事件侦听器添加到转发器内的 Flex 组件
我想为转发器内的每个组件添加一个事件侦听器,但不知道如何操作。这是我尝试过的一些代码:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用元数据中定义的事件,则只需添加 click="myClickHandler(event)" 即可。你也可以这样做:
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: