`

Flex中使用filter过滤数据

阅读更多


  1.  <?
    xml version="1.0" encoding="utf-8"?>  
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  creationComplete="init()" layout="absolute" fontSize="12" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FCFCFC, #FCFCFC]">  
  3.  <mx:Script>  
  4.   <![CDATA[ 
  5.   import mx.collections.ArrayCollection; 
  6.   import mx.events.CloseEvent; 
  7.   public var temp:String=""; 
  8.   [Bindable]private var filteredArr:Array; 
  9.      [Bindable]private var plistArr:Array; 
  10.      [Bindable]   
  11.         public var users:Array =[{id:1,username:"aaa", dept:"开发部"},    
  12.                         {id:2,username:"bbb", dept:"产品部"},    
  13.                      {id:3,username:"ccc", dept:"开发部"},                       
  14.                  {id:4,username:"ddd", dept:"产品部"}]; 
  15.        
  16.       private function init():void{ 
  17.         filteredArr = users.filter(removedDuplicates);  
  18.       } 
  19.       private var keys:Object = {};  
  20.       private function removedDuplicates(item:Object, idx:uint, arr:Array):Boolean {  
  21.                 if (keys.hasOwnProperty(item.dept)) {  
  22.                     return false;  
  23.                 } else {  
  24.                     keys[item.dept] = item;  
  25.                     return true;  
  26.                 }  
  27.             }  
  28.     
  29.       private function closeHandler(event:Event):void { 
  30.                 temp=String(ComboBox(event.target).selectedItem.dept); 
  31.                plistArr=users.filter(conditionFunction); 
  32.             } 
  33.  
  34.       private function conditionFunction(item:Object, idx:uint, arr:Array):Boolean {  
  35.                 if (item.dept==temp){ 
  36.                     return true ;   
  37.                 }else{ 
  38.                  return false; 
  39.                 } 
  40.                
  41.             }         
  42.   ]]>  
  43.  </mx:Script>  
  44.   <mx:Form width="293" height="152"  horizontalCenter="0" verticalCenter="0" borderStyle="solid">  
  45.     <mx:FormItem label="部门:" width="250">  
  46.        <mx:ComboBox   close="closeHandler(event);"  labelField="dept" dataProvider="{filteredArr}"  width="100%"></mx:ComboBox>  
  47.     </mx:FormItem>  
  48.     <mx:FormItem width="250">  
  49.        <mx:Repeater id="checkBoxRepeater" dataProvider="{plistArr}">   
  50.     <mx:CheckBox id="checkBox" label="{checkBoxRepeater.currentItem.username}"/>   
  51.    </mx:Repeater>   
  52.   
  53.     </mx:FormItem>  
  54.    
  55.  </mx:Form>  
  56. </mx:Application>  
  • 大小: 21.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics