一個很簡單的過濾下拉框
阿新 • • 發佈:2019-02-17
Java程式碼
第一次寫,很簡單的。過濾條件也很簡單,沒用到正則表示式。(懶的去查資料),item[_labelName]這個動態獲取屬性的方法很重要,多虧了網友的幫助。
- <?xml version="1.0" encoding="utf-8"?>
- <mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml" enter="toggleFilter(event)" editable="true">
- <mx:Script>
- <![CDATA[
- import com.eshangrao.util.ObjectKeyMap;
- import mx.events.FlexEvent;
- import mx.collections.ArrayCollection;
- //需要2個重要引數1.dataprovider:arrcoll 2.item.name的這個過濾屬性
- private var _labelName:String = "labelName";
- public function set labelName( value:String ) : void
- {
- _labelName = value;
- invalidateProperties();
- }
- public function get labelName() : String
- {
- return _labelName;
- }
- private function toggleFilter(event:FlexEvent):void{
- //trace(this.text);
- //trace(event.currentTarget.text);
- if (event.currentTarget.text!="") {
- //var filtStr:String=event.currentTarget.text;
- this.dataProvider.filterFunction = processFilter;
- } else {
- this.dataProvider.filterFunction = null;
- }
- this.dataProvider.refresh();
- }
- private function processFilter(item:Object):Boolean {
- //trace((String)(item.name));
- //trace((String)(item["name"]));
- return ((String)(item[_labelName])).indexOf(this.text)==0;
- }
- ]]>
- </mx:Script>
- </mx:ComboBox>
<?xml version="1.0" encoding="utf-8"?>
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml" enter="toggleFilter(event)" editable="true">
<mx:Script>
<![CDATA[
import com.eshangrao.util.ObjectKeyMap;
import mx.events.FlexEvent;
import mx.collections.ArrayCollection;
//需要2個重要引數1.dataprovider:arrcoll 2.item.name的這個過濾屬性
private var _labelName:String = "labelName";
public function set labelName( value:String ) : void
{
_labelName = value;
invalidateProperties();
}
public function get labelName() : String
{
return _labelName;
}
private function toggleFilter(event:FlexEvent):void{
//trace(this.text);
//trace(event.currentTarget.text);
if (event.currentTarget.text!="") {
//var filtStr:String=event.currentTarget.text;
this.dataProvider.filterFunction = processFilter;
} else {
this.dataProvider.filterFunction = null;
}
this.dataProvider.refresh();
}
private function processFilter(item:Object):Boolean {
//trace((String)(item.name));
//trace((String)(item["name"]));
return ((String)(item[_labelName])).indexOf(this.text)==0;
}
]]>
</mx:Script>
</mx:ComboBox>
第一次寫,很簡單的。過濾條件也很簡單,沒用到正則表示式。(懶的去查資料),item[_labelName]這個動態獲取屬性的方法很重要,多虧了網友的幫助。