0

我尝试使用 filterFunction 没有得到任何结果,看看这个例子:

[Bindable]
public  var SearchLoadlistOneDP:ArrayCollection;


public function SearchList():void {


 SearchLoadlistOneDP.filterFunction = filter;
 SearchLoadlistOneDP.refresh()


}


public function filter(item:Object):Boolean
{
 var beginsWithString:String = SearchLoadlistOneInput.text;



 return String(item["email"]).indexOf(beginsWithString) == 0;
}

我像这样使用数据网格:

<mx:DataGrid x="10" dataProvider="{SearchLoadlistOneDP}" y="49" width="891" height="408" id="listamail" creationComplete="LoadlistOne(0)">


     <mx:columns>
      <mx:DataGridColumn headerText="id" dataField="id" width="80"/>
      <mx:DataGridColumn headerText="E-mail" dataField="email"/>
      <mx:DataGridColumn headerText="Nome" dataField="nome"/>
     </mx:columns>


    </mx:DataGrid>

和这样的文本输入:

<s:TextInput x="62.6" y="9.75" width="408" id="SearchLoadlistOneInput" keyUp="SearchList()"  />

但不幸的是我没有任何结果,并且数据网格已经有来自数据库的数据已经列出了数据。

有谁能帮忙吗,谢谢大家了

4

2 回答 2

1

这是您的过滤器功能的外观。我已经使用这种方法一段时间了,并且没有遇到任何问题。这适用于 Flex 3 和 4。

private function filter(item:Object):Boolean{

    //this is going to return true if we don't have anything to search by, which will return 
   //all items the the datagrid
    if(SearchLoadlistOneInput.text == ""){
    return true;
    }

     //now search the string and see if we have a match//
    if(item.email.toLowerCase().search(SearchLoadlistOneInput.text.toLowerCase()) != -1){
       return true;
    }

    return false;
}
于 2011-08-10T12:28:01.983 回答
0

Flex SDK 4.0.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" minWidth="955" minHeight="600" applicationComplete="_init();">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [Bindable]
            public  var SearchLoadlistOneDP:ArrayCollection;

            private function _init() :void
            {
                SearchLoadlistOneDP = new ArrayCollection();
                SearchLoadlistOneDP.addItem({id: 1, email: 'fake@null.com', name:'Bill'});
                SearchLoadlistOneDP.addItem({id: 2, email: 'test@null.com', name:'Todd'});
                SearchLoadlistOneDP.addItem({id: 3, email: 'null@null.com', name:'Beth'});
                SearchLoadlistOneDP.addItem({id: 4, email: 'void@null.com', name:'Tiffany'});
            }

            public function SearchList():void {
                SearchLoadlistOneDP.filterFunction = filter;
                SearchLoadlistOneDP.refresh()
            }


            public function filter(item:Object):Boolean
            {
                var name:String = String(item["email"]);
                var beginsWithString:String = SearchLoadlistOneInput.text;

                return name.indexOf(beginsWithString) == 0;
            }
        ]]>
    </fx:Script>

    <mx:DataGrid x="10" dataProvider="{SearchLoadlistOneDP}" y="49" width="891" height="408" id="listamail">


        <mx:columns>
            <mx:DataGridColumn headerText="id" dataField="id" width="80"/>
            <mx:DataGridColumn headerText="E-mail" dataField="email"/>
            <mx:DataGridColumn headerText="Name" dataField="name"/>
        </mx:columns>


    </mx:DataGrid>


    <s:TextInput x="62.6" y="9.75" width="408" id="SearchLoadlistOneInput" keyUp="SearchList()"  />

</s:Application>
于 2010-07-26T05:39:17.877 回答