【永恒的瞬間】
          ?Give me hapy ?
          <? xml?version = " 1.0 " ?encoding = " utf-8 " ?>
          < mx:Application?xmlns:mx = " http://www.adobe.com/2006/mxml "
          ????????????????layout
          = " vertical "
          ????????????????creationComplete
          = " initApp() " >

          < mx:Script >
          <! [CDATA[

          ????
          // ?On?startup
          ???? public ?function?initApp(): void
          ????{
          ????????
          // ?Set?filter?function
          ????????
          // ?Be?careful?to?set?filterFunction
          ????????
          // ?only?after?ArrayCollection?has?been
          ????????
          // ?populated.
          ????????myData.filterFunction = processFilter;
          ????}

          ????
          // ?Filter?function
          ???? public ?function?processFilter(item:Object):Boolean
          ????{
          ????????var?result:Boolean
          = false ;

          ????????
          // ?If?no?filter?text,?or?a?match,?then?true
          ???????? if ?( ! item.name.length
          ????????????????
          || ?item.name.toUpperCase().indexOf(txtFilter.text.toUpperCase())? >= ? 0 )
          ????????result
          = true ;

          ????????
          return ?result;
          ????}
          ]]
          >
          </ mx:Script >

          <!-- ?Data?(use?ArrayCollection)? -->
          < mx:ArrayCollection?id = " myData " >
          ????
          < mx:source >
          ????????
          < mx:Object?name = " Ben?Forta "
          ????????????location
          = " Oak?Park,?MI "
          ????????????phone
          = " (248)555-5555 " ? />
          ????????
          < mx:Object?name = " Jane?Doe "
          ????????????location
          = " New?York,?NY "
          ????????????phone
          = " (212)555-1234 " ? />
          ????????
          < mx:Object?name = " Jim?Jones "
          ????????????location
          = " Atlanta,?GA "
          ????????????phone
          = " (414)555-1212 " ? />
          ????????
          < mx:Object?name = " Roberta?Roberts "
          ????????????location
          = " Chicago,?IL "
          ????????????phone
          = " (312)555-4321 " ? />
          ????????
          < mx:Object?name = " Steve?Stevens "
          ????????????location
          = " Boston,?MA "
          ????????????phone
          = " (617)555-5656 " ? />
          ????
          </ mx:source >
          </ mx:ArrayCollection >

          <!-- ?UI? -->
          < mx:HBox?width = " 100% " >
          ????
          < mx:Label?text = " Filter: " />
          ????
          < mx:TextInput?id = " txtFilter "
          ????????????width
          = " 100% "
          ????????????change
          = " myData.refresh() " />
          </ mx:HBox >

          < mx:DataGrid?dataProvider = " {myData} "
          ????????width
          = " 100% " ?height = " 100% " >
          ????
          < mx:columns >
          ????????
          < mx:DataGridColumn?headerText = " Name "
          ????????????????????dataField
          = " name " />
          ????????
          < mx:DataGridColumn?headerText = " Location "
          ????????????????????dataField
          = " location " />
          ????????
          < mx:DataGridColumn?headerText = " Phone " ????????????dataField = " phone " />
          ????
          </ mx:columns >
          </ mx:DataGrid >
          </ mx:Application >

          其中主要的是ArrayCollection的filterFunction屬性,他的使用方法如下:
          ArrayCollection的filterFunction屬性是繼承自ListCollectionView的,還有其他類具有這個功能,以下是一個繼承關系圖,詳細的可以看flex 的幫助文件
          filterFunction屬性的值是一個函數(Function):
          參數:Object類型的一個值,也可以不帶參數;
          返回值:Boolean類型的值,如果返回值為True就把這個Object放到里面,反之亦然。
          其函數格式事例如下:
          f(item:Object):Boolean
          在函數里面進行處理,以上的例子就是如此:
          ?public function processFilter(item:Object):Boolean
          ?{
          ?????? var result:Boolean=false;
          ????? //?查看文本框里的字符串長度或字符串的匹配(大小寫都可以),然后返回結果。
          ??????if (!item.name.length || item.name.toUpperCase().indexOf(txtFilter.text.toUpperCase()) >= 0)
          ??? ?result=true;
          ??? ?return result;
          ?}
          注意:filterFunction函數只有在對象建立的時候和調用reflash()的時候執行的,所以一定要在顯示之前調用下reflash(),否則顯示就不正常了,切記!切記!
          posted on 2007-01-23 10:21 ???MengChuChen 閱讀(691) 評論(0)  編輯  收藏 所屬分類: flex2.0
          主站蜘蛛池模板: 丰原市| 桓台县| 衡东县| 宿松县| 太白县| 调兵山市| 金昌市| 松溪县| 龙口市| 萍乡市| 漳平市| 义乌市| 富阳市| 翁牛特旗| 扎兰屯市| 连南| 旬阳县| 稻城县| 新干县| 海城市| 贵阳市| 庆元县| 广河县| 平远县| 北川| 伊川县| 白河县| 西乌珠穆沁旗| 彩票| 云和县| 长葛市| 东方市| 巴楚县| 宝清县| 清远市| 洪湖市| 徐闻县| 雷山县| 香格里拉县| 竹北市| 新竹县|