当复选框被选中/取消选中时,如何触发 Flex 列表中的 itemEditEnd 事件?

发布于 2024-07-26 00:20:09 字数 339 浏览 6 评论 0原文

我有一个 List 组件,它具有嵌入式 CheckBox itemEditor,它也充当 itemRenderer。 它将每个项目显示为带有标签的简单 CheckBox

但是,直到我单击列表之外的内容后,itemEditEnd 事件才会被触发。 我希望在选中或取消选中复选框后触发它。

我正在考虑在 CLICK 事件处理程序中手动调度 ListEvent.ITEM_EDIT_END ,但随后 itemEditEnd 事件将被调度两次。 一定有更好的方法来做到这一点。

有任何想法吗?

谢谢。

I have a List component that has drop-in CheckBox itemEditor that also serves as the itemRenderer. It displays each item as a simple CheckBox with a label.

However, the itemEditEnd Event does not get triggered until I click on something outside of the List. I want it triggered once the CheckBox is checked or unchecked.

I was thinking of manually dispatching the ListEvent.ITEM_EDIT_END in a CLICK Event handler, but then the itemEditEnd Event would get dispatched twice. There's gotta be a better way to do this.

Any ideas?

Thanks.

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

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

发布评论

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

评论(2

别闹i 2024-08-02 00:20:09

这是我想出的解决方案。 我更改了列表以使用该组件作为 itemRenderer,而不是作为 itemRenderer 和 itemEditor。 然后,我添加了一个 MouseEvent.CLICK 处理程序,以从 itemRenderer 调用列表中的函数来执行必要的操作:

我的列表组件:

package
{
    import mx.controls.List;
    import mx.core.ClassFactory;

    public class CustomCheckBoxList extends List
    {
        public function CustomCheckBoxList()
        {
            super();

            itemRenderer = new ClassFactory(CheckBoxRenderer);
        }

        public function dispatchSelectionEvent(item:Object, selected:Boolean):void
        {
            // Take action here...
        }
    }
}

我的 ItemRenderer:

package
{
    import flash.events.MouseEvent;

    import mx.controls.CheckBox;

    public class CheckBoxRenderer extends CheckBox
    {
        public function CheckBoxRenderer()
        {
            super();
        }

        override protected function clickHandler(event:MouseEvent):void
        {
            super.clickHandler(event);

            CustomCheckBoxList(listData.owner).dispatchSelectionEvent(data, selected);
        }
    }
}

Here is the solution I came up with. I changed my List to use the component as an itemRenderer only, not as a itemRenderer and itemEditor. I then added a MouseEvent.CLICK handler to call a function in the List from the itemRenderer to perform the necessary actions:

My List Component:

package
{
    import mx.controls.List;
    import mx.core.ClassFactory;

    public class CustomCheckBoxList extends List
    {
        public function CustomCheckBoxList()
        {
            super();

            itemRenderer = new ClassFactory(CheckBoxRenderer);
        }

        public function dispatchSelectionEvent(item:Object, selected:Boolean):void
        {
            // Take action here...
        }
    }
}

My ItemRenderer:

package
{
    import flash.events.MouseEvent;

    import mx.controls.CheckBox;

    public class CheckBoxRenderer extends CheckBox
    {
        public function CheckBoxRenderer()
        {
            super();
        }

        override protected function clickHandler(event:MouseEvent):void
        {
            super.clickHandler(event);

            CustomCheckBoxList(listData.owner).dispatchSelectionEvent(data, selected);
        }
    }
}
花落人断肠 2024-08-02 00:20:09

我刚刚遇到这个。 我使用的是自定义组件而不是直接插入方法,这在使用渲染器作为编辑器时有效。

请注意,Flex 人员显然提出了这样的想法:用户希望在确定要提交的状态之前多次切换复选框……此时他们会按 Enter 键。 多么明显啊!

我的解决方案是合成一个相当于按 Enter 的键盘事件。 棘手的部分是必须使用 callLater() 方法来调度事件,因为在调用复选框的单击处理程序之前,列表控件不会在编辑器上注册其键盘侦听器。 这是我的自定义渲染器/编辑器组件中复选框的单击处理程序:

private function onClick(value:Object):void {
    newValue = value;
    var list:ListBase = ListBase(owner);
    list.callLater(dispatchEvent, [new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, false, Keyboard.ENTER, Keyboard.ENTER)]); 
}

I've just run into this. I'm using a custom component rather than the drop-in approach, and this works when using the renderer as the editor.

Note that the Flex folks evidently came up with the notion that users would want to toggle their checkboxes a few times before settling on the state to commit to...at which point they'd hit the Enter key. How obvious!

My solution is to synthesize a keyboard event that is equivalent to hitting Enter. The tricky part is that one must use the callLater() method to dispatch the event because the list control won't have registered its keyboard listener on the editor until after the checkbox's click handler gets called. Here's my click handler for the checkbox in my custom renderer/editor component:

private function onClick(value:Object):void {
    newValue = value;
    var list:ListBase = ListBase(owner);
    list.callLater(dispatchEvent, [new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, false, Keyboard.ENTER, Keyboard.ENTER)]); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文