Flex树空间默认事件监听器

发布于 2024-09-26 19:45:35 字数 48 浏览 2 评论 0原文

我注意到,当我选择树节点时,如果单击空间,所选节点就会打开...我如何删除此事件?

I have noticed that when I select tree node if space is clicked the selected node gets opened... how could I remove this event?

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

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

发布评论

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

评论(1

孤单情人 2024-10-03 19:45:36

看起来没有办法阻止该事件,如果有的话,我不确定这是否明智,因为 Tree 的 keyDownHandler 所做的不仅仅是打开节点。

我通过创建自定义树解决了这个问题。遗憾的是我不得不从树的 keyDownHandler 中复制几行代码。

public class MyTree extends Tree
{
    override protected function keyDownHandler(event:KeyboardEvent):void
    {
        if (event.keyCode == Keyboard.SPACE)
        {
            // Code copied from Tree's keyDownHandler

            // if user has moved the caret cursor from the selected item
            // move the cursor back to selected item
            if (caretIndex != selectedIndex)
            {
                // erase the caret
                var renderer:IListItemRenderer = indexToItemRenderer(caretIndex);

                if (renderer)
                    drawItem(renderer);
                caretIndex = selectedIndex;
            }

            event.stopImmediatePropagation();
        }
        else
        {
            super.keyDownHandler(event);
        }
    }
}

It doesn't look like there's a way to prevent the event and if there is one I'm not sure it's wise since the Tree's keyDownHandler does a little bit more than just opening the node.

I solved it by creating a custom Tree. Sadly I had to copy a few lines of code from the Tree's keyDownHandler.

public class MyTree extends Tree
{
    override protected function keyDownHandler(event:KeyboardEvent):void
    {
        if (event.keyCode == Keyboard.SPACE)
        {
            // Code copied from Tree's keyDownHandler

            // if user has moved the caret cursor from the selected item
            // move the cursor back to selected item
            if (caretIndex != selectedIndex)
            {
                // erase the caret
                var renderer:IListItemRenderer = indexToItemRenderer(caretIndex);

                if (renderer)
                    drawItem(renderer);
                caretIndex = selectedIndex;
            }

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