Flex 可编辑组合框

发布于 2024-12-22 12:09:15 字数 464 浏览 1 评论 0原文

我正在为我的应用程序使用可编辑组合框。组合框具有默认行为,例如

如果我输入一些与组合框数据提供程序值不相似的文本,则组合框默认选择第一个数据提供程序值并关闭下拉窗口。我想停止这种默认行为。

前任。我有带有 dataprovider 值的组合框。 (堆栈、stackoverflow、stackoverflow A) 我打开下拉列表,看到“stackoverflow A”值位于下拉列表中。现在我输入值“stackoverflow B”,但该值不在下拉列表中,因此当我输入时,组合框会覆盖我输入的文本,并将“stackoverflow B”替换为 dataprovider(dropdown)“stack”的第一个值,并触发 selectedindex 更改事件。我想停止默认选择第一个值的组合框的默认行为并查找输入的值。

我尝试过将 selectedindex 默认设置为 -1,但默认情况下它仍然采用第一个值。任何解决方法或建议都会有所帮助。

谢谢

I am using editable combobox for my application. Combobox have default behavior like

If I enter some text which is not similar to the combobox dataprovider values, combobox by default select first dataprovider value and close the dropdown window. I want stop this default behavior.

Ex. I have combobox with the dataprovider value. (stack, stackoverflow, stackoverflow A)
I open the dropdown and see the "stackoverflow A" value is in the dropdown. Now I enter value "stackoverflow B" but this value is not in the dropdown so when I enter, combobox override my entered text and replace "stackoverflow B" with first value of dataprovider(dropdown) "stack" and fire the selectedindex change event. I want to stop default behavior of combobox of selection of first value by default and look for entered value.

I have tried doing selectedindex to -1 by default but its still taking the first value by default. Any work around or suggestion would be helpful.

thanks

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

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

发布评论

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

评论(2

可是我不能没有你 2024-12-29 12:09:15

我认为这会对您有所帮助...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" horizontalAlign="center" 
verticalAlign="middle" height="100%" width="100%">

<mx:Script>
    <![CDATA[
        public var arr:Array = new Array({isSelected:true,label:'ABC',score:'78',name:'ABC'},
                                         {isSelected:true,label:'DEF',score:'50',name:'DEF'},
                                         {isSelected:false,label:'GHI',score:'70',name:'GHI'},
                                         {isSelected:false,label:'JKL',score:'80',name:'JKL'},
                                         {isSelected:true,label:'TRE',score:'50',name:'MNO'});

        public function dgCLG_dataChange():void
        {

        }

        public function dgCLG_change():void
        {

        }

        public function btnSubmit_click():void
        {
            dgCopy.dataProvider = dgCLG.dataProvider;
        }

    ]]>
</mx:Script>

<mx:VBox height="100%" width="100%" horizontalAlign="center" verticalAlign="middle">
    <mx:DataGrid id="dgCLG" dataProvider="{arr}" editable="true" dataChange="{dgCLG_dataChange();}" change="{dgCLG_change();}">
        <mx:columns>
            <mx:DataGridColumn headerText="" dataField="isSelected">
                <mx:itemRenderer>
                    <mx:Component>
                        <mx:Box horizontalAlign="center" verticalAlign="middle" height="100%" width="100%">
                            <mx:Script>
                                <![CDATA[
                                    override public function set data(value:Object):void
                                    {
                                        if(value != null)
                                        {
                                            super.data = value;
                                            var temp:Object = value as Object;
                                            chb.selected = temp.isSelected;
                                        }
                                    }
                                ]]>
                            </mx:Script>
                            <mx:CheckBox id="chb"/>
                        </mx:Box>
                    </mx:Component>                     
                </mx:itemRenderer>
            </mx:DataGridColumn>
            <mx:DataGridColumn headerText="Label" dataField="label" editable="false">

            </mx:DataGridColumn>
            <mx:DataGridColumn dataField="name" headerText="Person" itemEditor="ComCB" editorDataField="value" editable="true">

            </mx:DataGridColumn>
        </mx:columns>
    </mx:DataGrid>  

    <mx:Button id="btnSubmit" label="Click" click="{btnSubmit_click();}" />

    <mx:DataGrid id="dgCopy" editable="false">
        <mx:columns>
            <mx:DataGridColumn headerText="CopyLabel" dataField="label" />
            <mx:DataGridColumn headerText="CopyMarks" dataField="score" />
            <mx:DataGridColumn headerText="CopyPerson" dataField="name" />
        </mx:columns>
    </mx:DataGrid>
</mx:VBox>

</mx:Application>

这是 ComCb 组件。

<?xml version="1.0" encoding="utf-8"?>
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml" dataProvider="{arr}" selectedIndex="1" creationComplete="{c_complete();}" >
<mx:Script>
    <![CDATA[
        public var arr:Array = new Array({label:'ABC'},{label:'DEF'},{label:'GHI'},{label:'JKL'},{label:'MNO'},{label:'XXX'})

        public function c_complete():void
        {
            for(var i:int = 0; i < arr.length; i++)
            {
                if(arr[i].label == parentDocument.dgCLG.selectedItem.name)
                {
                    this.selectedItem = arr[i];
                }
            }   
        }
    ]]>
</mx:Script>
</mx:ComboBox>

也许这会对你有帮助......

祝你度过愉快的一天......

I think this will gonna be helpful to you...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" horizontalAlign="center" 
verticalAlign="middle" height="100%" width="100%">

<mx:Script>
    <![CDATA[
        public var arr:Array = new Array({isSelected:true,label:'ABC',score:'78',name:'ABC'},
                                         {isSelected:true,label:'DEF',score:'50',name:'DEF'},
                                         {isSelected:false,label:'GHI',score:'70',name:'GHI'},
                                         {isSelected:false,label:'JKL',score:'80',name:'JKL'},
                                         {isSelected:true,label:'TRE',score:'50',name:'MNO'});

        public function dgCLG_dataChange():void
        {

        }

        public function dgCLG_change():void
        {

        }

        public function btnSubmit_click():void
        {
            dgCopy.dataProvider = dgCLG.dataProvider;
        }

    ]]>
</mx:Script>

<mx:VBox height="100%" width="100%" horizontalAlign="center" verticalAlign="middle">
    <mx:DataGrid id="dgCLG" dataProvider="{arr}" editable="true" dataChange="{dgCLG_dataChange();}" change="{dgCLG_change();}">
        <mx:columns>
            <mx:DataGridColumn headerText="" dataField="isSelected">
                <mx:itemRenderer>
                    <mx:Component>
                        <mx:Box horizontalAlign="center" verticalAlign="middle" height="100%" width="100%">
                            <mx:Script>
                                <![CDATA[
                                    override public function set data(value:Object):void
                                    {
                                        if(value != null)
                                        {
                                            super.data = value;
                                            var temp:Object = value as Object;
                                            chb.selected = temp.isSelected;
                                        }
                                    }
                                ]]>
                            </mx:Script>
                            <mx:CheckBox id="chb"/>
                        </mx:Box>
                    </mx:Component>                     
                </mx:itemRenderer>
            </mx:DataGridColumn>
            <mx:DataGridColumn headerText="Label" dataField="label" editable="false">

            </mx:DataGridColumn>
            <mx:DataGridColumn dataField="name" headerText="Person" itemEditor="ComCB" editorDataField="value" editable="true">

            </mx:DataGridColumn>
        </mx:columns>
    </mx:DataGrid>  

    <mx:Button id="btnSubmit" label="Click" click="{btnSubmit_click();}" />

    <mx:DataGrid id="dgCopy" editable="false">
        <mx:columns>
            <mx:DataGridColumn headerText="CopyLabel" dataField="label" />
            <mx:DataGridColumn headerText="CopyMarks" dataField="score" />
            <mx:DataGridColumn headerText="CopyPerson" dataField="name" />
        </mx:columns>
    </mx:DataGrid>
</mx:VBox>

</mx:Application>

Here is the ComCb Component.

<?xml version="1.0" encoding="utf-8"?>
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml" dataProvider="{arr}" selectedIndex="1" creationComplete="{c_complete();}" >
<mx:Script>
    <![CDATA[
        public var arr:Array = new Array({label:'ABC'},{label:'DEF'},{label:'GHI'},{label:'JKL'},{label:'MNO'},{label:'XXX'})

        public function c_complete():void
        {
            for(var i:int = 0; i < arr.length; i++)
            {
                if(arr[i].label == parentDocument.dgCLG.selectedItem.name)
                {
                    this.selectedItem = arr[i];
                }
            }   
        }
    ]]>
</mx:Script>
</mx:ComboBox>

might be this will gonna helpful to you...

Have a NICE D@y.......

盛装女皇 2024-12-29 12:09:15

还有一个替代的方法:它不会尝试将文本与数据提供程序值进行匹配(如上所述),并且没有 这个错误。它是一个仅 ActionScript、Flex、spark 的组合框,可作为 打开来源

There is an alternative to the <s:ComboBox> which does not attempt to match text with the data provider values (as described above), and does not have this bug. It is an ActionScript, Flex, spark only combo box, and is available as open source.

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