apache-flex 下拉项目中未选中复选框rendere flex

omqzjyyz  于 2022-11-01  发布在  Apache
关注(0)|答案(1)|浏览(125)

我有DropDownlist,它有如下的Itemrenderer:

<s:DropDownList dataProvider="{testList}" labelField="test" 
                        itemRenderer="DropDownSelectRenderer"/>

项目渲染器:

<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" >

<fx:Script>
        <![CDATA[

            protected function onChange(event:Event):void
            {
                trace("checked");
            }

        ]]>
    </fx:Script>

<s:CheckBox id="chkBox" selected="{data.selected}" change="onChange(event)"  />
<s:Label id="lblCon" fontSize="14" text="{data.test}"  />

</s:ItemRenderer>

我希望CheckBox chkBox在单击事件上更改并标记为lblCon
但是当我打开Dropdown并试图单击CheckBox时,Dropdown关闭了,CheckBox没有选中。
任何帮助都是感激不尽的。

of1yzvn4

of1yzvn41#

您可能需要使用PopUpButton,如下所示:

<?xml version="1.0"?>
<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">
<fx:Script><![CDATA[
    import mx.collections.ArrayCollection;

    [Bindable]
    private var testList:ArrayCollection = new ArrayCollection([
        {"test":"Test A", "selected": false},
        {"test":"Test B", "selected": true},
        {"test":"Test C", "selected": false},
        {"test":"Test D", "selected": false}
    ]);
    protected function closeButtonClickHandler(event:MouseEvent):void {
        testPopUp.close();
    }
    ]]></fx:Script>
<mx:PopUpButton id="testPopUp"
                width="150">
    <mx:popUp>
        <mx:VBox width="150" backgroundColor="0xd3d3d3">
            <mx:List id="list"
                     dataProvider="{testList}"
                     height="{testList.length * 25}"
                     width="100"
                     borderStyle="none">
                <mx:itemRenderer>
                    <fx:Component>
                        <mx:CheckBox height="20">
                            <fx:Script>
                                <![CDATA[
                                override public function set data(value:Object):void
                                {
                                    super.data = value;
                                    if (value && value.test)
                                    {
                                        super.label = value.test;
                                        super.selected = value.selected;
                                    }
                                }
                                ]]>
                            </fx:Script>
                        </mx:CheckBox>
                    </fx:Component>
                </mx:itemRenderer>
            </mx:List>
            <mx:Button label="Close"
                       click="closeButtonClickHandler(event)"/>
        </mx:VBox>
    </mx:popUp>
</mx:PopUpButton>
</s:Application>

相关问题