0

我有一个组合框,我为其实现了自定义过滤器,组合框代码如下所示

<fx:Declarations>
        <s:ArrayCollection id="arrC">
            <vo:ValueObject firstValue="430" secondValue="sampath"/>
            <vo:ValueObject firstValue="105" secondValue="New York"/>
            <vo:ValueObject firstValue="896" secondValue="Xerox"/>
        </s:ArrayCollection>
    </fx:Declarations>

private function combineFunction(item:Object):String {
                return item.firstValue+"-"+item.secondValue;
            }

<local:AwadComboBox x="325" y="212" id="cb" dataProvider="{arrC}" labelFunction="combineFunction"/>

组合框是使用扩展组合框的自定义过滤器实现的

private var unfilteredDataProvider : IList;
            override public function set dataProvider(value:IList):void {
                super.dataProvider = value;

                unfilteredDataProvider = value;
            }

            override protected function textInput_changeHandler(event:TextOperationEvent):void {
                super.textInput_changeHandler(event);

                if (unfilteredDataProvider is ArrayCollection) {
                    ArrayCollection(unfilteredDataProvider).filterFunction = filterMatches;
                    ArrayCollection(unfilteredDataProvider).refresh();

                    super.dataProvider = new ArrayCollection(unfilteredDataProvider.toArray()); 
                }
            }

            protected function filterMatches(item:Object):Boolean {
                if (item is String) {
                    if(String(item).toLowerCase().indexOf(
                        textInput.text.slice(0,
                            textInput.selectionAnchorPosition).toLowerCase())>-1)
                        return true;
                }
                else if (labelField && labelField!= "") {
                    if(item.hasOwnProperty(labelField) && 
                        String(item[labelField]).toLowerCase().indexOf(
                            textInput.text.slice(0,
                                textInput.selectionAnchorPosition).toLowerCase())>-1)
                        return true;
                }

                return false;
            }

在此组合框中,无论您输入的字符如何,如果该字符在下拉列表中,则应过滤该值,但我的代码中有一个错误,有人可以帮我解决这个问题。

谢谢!

4

0 回答 0