ComboBox 筛选 过滤

[java]  view plain copy
  1. package skins.my  
  2. {     
  3.     import mx.collections.ArrayCollection;  
  4.     import mx.utils.StringUtil;  
  5.       
  6.     import spark.components.ComboBox;  
  7.     import spark.events.TextOperationEvent;  
  8.       
  9.     public class ComboBoxFilter extends ComboBox  
  10.     {  
  11.         public function ComboBoxFilter()  
  12.         {  
  13.             super();  
  14.         }  
  15.           
  16.         private var _dataSource:ArrayCollection;  
  17.         [Bindable]  
  18.         public function get dataSource():ArrayCollection{  
  19.             return _dataSource;  
  20.         }  
  21.         public function set dataSource(value:ArrayCollection):void{  
  22.               
  23.             this._dataSource=value;  
  24.             if(_dataSource!=null&&_dataSource.length>0){  
  25.                 this.dataProvider = new ArrayCollection(_dataSource.toArray());  
  26.             }  
  27.         }  
  28.           
  29.         override protected function textInput_changeHandler(event:TextOperationEvent):void{  
  30.             if(_dataSource!=null&&_dataSource.length>0){  
  31.                 var array:ArrayCollection = new ArrayCollection(dataSource.toArray());  
  32.                 array.filterFunction = dataSourceFilterFunction;  
  33.                 array.refresh();  
  34.                 this.dataProvider = new ArrayCollection(array.toArray());  
  35.                   
  36.                 if(this.dataProvider!=null&&this.dataProvider.length>0){  
  37.                     super.textInput_changeHandler(event);  
  38.                 }  
  39.             }  
  40.         }  
  41.           
  42.         private function dataSourceFilterFunction(obj:Object):Boolean{  
  43.             var str:String="";  
  44.             if(labelField!=null){  
  45.                 str=(obj[labelField]!=null?obj[labelField].toString():"");  
  46.             }else{  
  47.                 str=obj.toString();  
  48.             }  
  49.             if(StringUtil.trim(this.textInput.text).length==0){  
  50.                 return true;  
  51.             }else if(str.indexOf(StringUtil.trim(this.textInput.text))>-1){  
  52.                 return true;  
  53.             }else{  
  54.                 return false;  
  55.             }  
  56.         }  
  57.           
  58.     }  
  59. }  


调用代码如下:

[html]  view plain copy
  1. <my:ComboBoxFilter id="combo2" width="200" labelField="cpb002" dataSource="{绑定集合}" focusIn="IME.enabled=true"/>  

转载:http://blog.csdn.net/hellofr/article/details/7543017

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值