【问题标题】:Actionscript 3 filter items out of comboboxActionscript 3 从组合框中过滤项目
【发布时间】:2017-07-21 09:00:54
【问题描述】:

所以我有一个应该按如下方式工作的组合框:

  1. 点击下拉菜单
  2. 选择一个项目
  3. 项目被移动到另一个列表中
  4. 项目无法再在第一个组合框下拉列表中找到

所以我创建了一个组合框,如下所示:

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

我的问题源于调用objects.refresh(),因为它在dataGroup.removeEventListener(FlexEvent.UPDATE_COMPLETE, updateCompleteListenerA); 行的list.as 文件(AS 库)中失败,其中dataGroup 为空。

我在objects ArrayCollection 上的过滤功能类似于:

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;
}

我在更改处理程序结束时调用刷新。

【问题讨论】:

    标签: actionscript-3 combobox mxml


    【解决方案1】:

    对于您的问题,有一个更简单的解决方案。我刚刚测试了它。 首先你需要声明你的组合框:

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

    然后你在更改处理程序上使用这个函数:

    private function updateList(event:IndexChangeEvent):void
    {
        secondaryCombobox.dataProvider.addItem(primaryCombobox.selectedItem);
        primaryCombobox.dataProvider.removeItemAt(primaryCombobox.selectedIndex);
    }
    

    【讨论】:

    • 我有同样的问题,删除一个项目不会更新组合框,所以我必须调用.refresh(),随后失败。
    • 尽量不要将 DataProvider 与 DataBinding 一起使用。这就是它对我有用的方式。您可以稍后在更改事件处理程序中模仿数据绑定。 myCombobox.dataProvider = someArrayList;
    • 有趣,我真的很想知道为什么我的数据过滤器会导致问题。我删除了绑定,但刷新仍然失败。
    • 使用我的代码,您实际上不需要调用 refresh(),因为所有更改都会立即应用。只需尝试将示例复制并粘贴到空白项目中即可查看交互。
    • 对,但我的问题源于未应用更改,不得不调用刷新,然后它失败了。我在我的项目中尝试了您的解决方案,但它没有按预期工作。
    猜你喜欢
    • 2010-12-29
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 2011-01-01
    • 1970-01-01
    • 2010-12-29
    • 2013-12-04
    • 1970-01-01
    相关资源
    最近更新 更多