Using the filter filtering data in Flex

Recommended for you: Get network issues from WhatsUp Gold. Not end users.


  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:"Development Department"},    
  12.                         {id:2,username:"bbb", dept:"Product department"},    
  13.                      {id:3,username:"ccc", dept:"Development Department"},                       
  14.                  {id:4,username:"ddd", dept:"Product department"}]; 
  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="Department: " 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>  
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Nathaniel at December 22, 2013 - 7:53 PM