以交互方式从组合框中删除元素

发布于 2024-10-24 11:25:42 字数 2447 浏览 3 评论 0原文

我正在使用 Spark 组合框(我真的很喜欢)。我想做的是允许用户从 cb 列表中删除元素。为此,我想通过使用自定义(且非常简单)的 itemRenderer 在每个 cb 元素旁边添加一个删除按钮。

一切看起来都不错 - 我可以显示一个按钮,并且该按钮看起来是交互式的(即,如果您将鼠标悬停在它上面,它的颜色肯定会改变)。但是,当我单击按钮时,我似乎无法触发任何事件。我浏览了该组件的代码,但没有被任何天才的想法所启发。我想知道是否有人知道如何获得拍摄按钮(我可以从那里拿走它......)。这是一些示例代码来解释发生了什么...

谢谢大家!


<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

    <fx:Declarations>
        <s:ArrayList id="dp">
            <fx:Object description="aaaa" />
            <fx:Object description="bbbb" />
            <fx:Object description="cccc" />
            <fx:Object description="dddd" />
        </s:ArrayList>
    </fx:Declarations>

    <s:ComboBox id="cb" width="200" x="20" y="20"
                dataProvider="{dp}" labelField="description"
                itemRenderer="ComboBoxItemRenderer.symbolComboBoxRenderer"/>

</s:Application>

和项目渲染器(注意:我尝试打开和关闭捕获阶段,但没有运气。我还尝试了更高的优先级,但也没有运气)。

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:s="library://ns.adobe.com/flex/spark"
                xmlns:mx="library://ns.adobe.com/flex/mx" width="100%"
                creationComplete="itemrenderer1_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            import mx.utils.StringUtil;

            import spark.components.ComboBox;

            override public function set data(value:Object):void  
            {
                super.data = value;
            }

            protected function button1_clickHandler(event:MouseEvent):void
            {
                trace("pressed button");
            }

            protected function itemrenderer1_creationCompleteHandler(event:FlexEvent):void
            {
                bt.addEventListener(MouseEvent.CLICK, button1_clickHandler, true, 50);
            }

        ]]>
    </fx:Script>

    <s:HGroup width="100%">
        <s:Label id="labelDisplay" left="1" top="5" bottom="5" width="100%"/>
        <s:Button id="bt" width="7" height="7"/>
    </s:HGroup>
</s:ItemRenderer>

I'm using a spark combobox (which I really like). What I'd like to do is to allow users to delete elements from the cb list. To do this, I thought I'd add a delete button next to each cb element, by using a custom (and extremely simple) itemRenderer.

All seemed ok - I can get a button to show up, and the button seems interactive (i.e. if you hover over it its color definitely changes). However, I can't seem to get any event to fire when I click on the button. I looked through the component's code but was not illuminated by any genius thought. I was wondering if anyone knows how to get the button to shoot (I can take it from there...). Here's some sample code to explain what's going on...

thank you all!


<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

    <fx:Declarations>
        <s:ArrayList id="dp">
            <fx:Object description="aaaa" />
            <fx:Object description="bbbb" />
            <fx:Object description="cccc" />
            <fx:Object description="dddd" />
        </s:ArrayList>
    </fx:Declarations>

    <s:ComboBox id="cb" width="200" x="20" y="20"
                dataProvider="{dp}" labelField="description"
                itemRenderer="ComboBoxItemRenderer.symbolComboBoxRenderer"/>

</s:Application>

and the item renderer (note: i tried both capture phase on and off, but no luck. Also I tried higher priority, but no luck there either).

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:s="library://ns.adobe.com/flex/spark"
                xmlns:mx="library://ns.adobe.com/flex/mx" width="100%"
                creationComplete="itemrenderer1_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            import mx.utils.StringUtil;

            import spark.components.ComboBox;

            override public function set data(value:Object):void  
            {
                super.data = value;
            }

            protected function button1_clickHandler(event:MouseEvent):void
            {
                trace("pressed button");
            }

            protected function itemrenderer1_creationCompleteHandler(event:FlexEvent):void
            {
                bt.addEventListener(MouseEvent.CLICK, button1_clickHandler, true, 50);
            }

        ]]>
    </fx:Script>

    <s:HGroup width="100%">
        <s:Label id="labelDisplay" left="1" top="5" bottom="5" width="100%"/>
        <s:Button id="bt" width="7" height="7"/>
    </s:HGroup>
</s:ItemRenderer>

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

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

发布评论

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

评论(1

挽袖吟 2024-10-31 11:25:42

好吧,想通了 - 重写 item_mouseDownHandler 并检查目标类型似乎可以解决问题。

ok, figured it out - overriding item_mouseDownHandler and checking for the target type seems to do the trick.

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