Flex 使用ArrayCollection的FilterFunction进行数据过滤

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout
="absolute" fontFamily="simsun" fontSize="12"
     creationComplete
="hs.send()">
    
<mx:Script>
        
<![CDATA[
            import mx.collections.ArrayCollection;
            import mx.rpc.events.*;
            import mx.controls.Alert;
            
            private function hsFault(event:FaultEvent):void{
                Alert.show(event.message.toString(),"Error");
            }
            private function hsResult(event:ResultEvent):void{
                
                mydata = event.result.NewDataSet.Table as ArrayCollection;
                mydata.filterFunction = NameFilterChanged;
                mydata.refresh();
            }
            public function NameFilterChanged(item:Object):Boolean{
                var name:String = item.姓名;
                var sno:String = item.学号;
                var sex:String = item.性别;
                if(cmbSex.selectedItem.data != "全部")
                    return (sno.indexOf(txtSNO.text,0) >= 0) &&(name.indexOf(txtName.text,0) >= 0) && (cmbSex.selectedItem.data == sex);
                else
                    return (sno.indexOf(txtSNO.text,0) >= 0) &&(name.indexOf(txtName.text,0) >= 0);
            }
            
            [Bindable]
            private    var mydata:ArrayCollection;

            
        
]]>
    
</mx:Script>
    
<mx:HTTPService id="hs" useProxy="false" url="绿色通道名单.xml" fault="hsFault(event)"
     showBusyCursor
="true" result="hsResult(event)"/>
    
<mx:DataGrid dataProvider="{mydata}" right="10" left="9" top="38" bottom="20" >
        
<mx:columns>
            
<mx:DataGridColumn headerText="姓名" dataField="姓名"/>
            
<mx:DataGridColumn headerText="性别" dataField="性别"/>
            
<mx:DataGridColumn headerText="学号" dataField="学号"/>
            
<mx:DataGridColumn headerText="准考证号" dataField="准考证号"/>
            
<mx:DataGridColumn headerText="生源地" dataField="生源地"/>
            
<mx:DataGridColumn headerText="身份" dataField="身份"/>
            
<mx:DataGridColumn headerText="户口" dataField="户口"/>
            
<mx:DataGridColumn headerText="部门" dataField="部门"/>
            
<mx:DataGridColumn headerText="原因" dataField="原因"/>
            
<mx:DataGridColumn headerText="财务处是否办理" dataField="财务处是否办理"/>
        
</mx:columns>
    
</mx:DataGrid>
    
<mx:Label x="186" y="12" text="姓名:"/>
    
<mx:TextInput id="txtName" x="229" y="10" change="{mydata.refresh()}" width="95"/>
    
<mx:ComboBox x="391" y="10" width="94" id="cmbSex" labelField="title" change="mydata.refresh()"> 
        
<mx:dataProvider>
            
<mx:Array>
                
<mx:Object title = "全部" data="全部"/>
                
<mx:Object title = "男" data="男"/>
                
<mx:Object title = "女" data="女"/>
            
</mx:Array>
        
</mx:dataProvider>
    
</mx:ComboBox>
    
<mx:Label x="348" y="12" text="性别:"/>
    
<mx:TextInput x="76" y="10" width="102" id="txtSNO" change="{mydata.refresh()}"/>
    
<mx:Label x="33" y="12" text="学号:"/>
</mx:Application>

Flex 使用ArrayCollection的FilterFunction进行数据过滤_第1张图片
 评论这张
转发至微博


转载:http://lindor888.blog.163.com/blog/static/46620760200831845014977/

你可能感兴趣的:(Flex 使用ArrayCollection的FilterFunction进行数据过滤)