Actionscript 3 filter items out of combobox

So I have a combobox that should work as follows:

  • Click dropdown
  • Choose an item
  • item is moved into another list
  • Item can no longer be found in first combobox dropdown
  • So I created a combobox like:

        <s:ComboBox
                id="cbox"
                labelFunction="labels"
                dataProvider="{objects}"
                change="addFilter()"
                restrict="a-zA-Z0-9-,_"
                width="100%"
                maxChars="32"
                prompt="add filter"
        />
    

    My issue stems from calling objects.refresh() , as it fails in the list.as file (AS library) at the line dataGroup.removeEventListener(FlexEvent.UPDATE_COMPLETE, updateCompleteListenerA); , where the dataGroup is null.

    My filter function on the objects ArrayCollection is something like:

    private function filterEcus(item:Object):Boolean {
         for each (var i:Object in secondList) {
            if (i.property == item.property) {
                return true;
            } else {
                return false;
            }
        }
        //should not reach this
        return true;
    }
    

    I call the refresh at the end of the change handler.


    There's a simpler solution for your problem. I just tested it. First you need to declare your comboboxes:

    <s:ComboBox id="primaryCombobox" change="updateList(event)">
        <s:ArrayList>
            <fx:Object label="One"/>
            <fx:Object label="Two"/>
            <fx:Object label="Three"/>
            <fx:Object label="Four"/>
        </s:ArrayList>
    </s:ComboBox>
    
    <s:ComboBox id="secondaryCombobox">
        <s:ArrayList>
            <!-- You need to declare an empty data provider. -->
        </s:ArrayList>
    </s:ComboBox>
    

    Then you use this function on the change handler:

    private function updateList(event:IndexChangeEvent):void
    {
        secondaryCombobox.dataProvider.addItem(primaryCombobox.selectedItem);
        primaryCombobox.dataProvider.removeItemAt(primaryCombobox.selectedIndex);
    }
    
    链接地址: http://www.djcxy.com/p/34588.html

    上一篇: ItemRenderer高度(和高度更改)不反映在AdvancedDataGrid行中

    下一篇: Actionscript 3从组合框中过滤项目