English 中文(简体)
• 如何在弹性数据网数据网中搜索插座 供应者4
原标题:How to search a string within a flex datagrid dataProvider 4?

我在利用过滤功能进行审判时没有取得任何结果。

[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()"  />

但不幸的是,我无法取得任何结果,而数据网已经拥有数据库中的数据。

谁能帮助? 谢谢大家。

问题回答

这里,你的过滤功能应当看重。 我一直在使用这一方法,并且没有问题。 这部工程有弹性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;
}

灵活性 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>




相关问题
Using one data source for multiple datagrids in Flex3

I want to use one data source (e.g. an Array) for multiple Datagrids that have different filterFunctions attached and show different columns. First, I thought I use a very straight forward apporach: ...

Load Content into TextInput Flex?

I ve got content coming into my application using a query and an ArrayCollection. I know how to display the content into a DataGrid by using the dataProvider propriety, but I d like to use TextInput ...

How to get the memory size of an ArrayCollection in Flex

I have built an image cache which is an ArrayCollection containing images. I have built functionality so that the cache can hold a max of 250 images. However, the images can be of a different size, so ...

Flex XML dynamic type

I have an application which receives dynamic XML data from a server. The structure of the XML is dynamic and the tags/attribute names cannot be predicted. NO row items can be hardcoded. The data is ...

Flex looping through object

Im trying to extend the flex ArrayCollection to be able to search for an object containing specific data and give it back. Here is my function: public function getItemContaining(value: String): ...

热门标签