Flex 4.6 XML搜尋、匹配樣本,完整代碼

來源:互聯網
上載者:User

原文同步至:  http://www.waylau.com/flex-4-6-xml-search-sample-matches/

效果見圖

初始化介面

輸入“設定”,進行搜尋、匹配後介面

下面是代碼

<?xml version="1.0" encoding="utf-8"?><s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"    xmlns:s="library://ns.adobe.com/flex/spark"    xmlns:mx="library://ns.adobe.com/flex/mx"    minWidth="955" minHeight="600" creationComplete="init(event)"><fx:Script><![CDATA[import mx.events.FlexEvent;import mx.utils.StringUtil;import spark.events.TextOperationEvent;public var rawList:XML = <apps name="應用程式" >  <item name="關於"  icon="plugins/about_002/assets/icons/about_48.png"   iconSmall="plugins/about_002/assets/icons/about_24.png"   moduleUrl="plugins/about_002/Ahout_002.swf"  version="1.0"  date="2013-5-13"  author="way" type="plugin"  description="關於能源管理中心的一個說明" /> <item name="程式管理"   icon="plugins/appManager_001/assets/icons/apps_48.png"   iconSmall="plugins/appManager_001/assets/icons/apps_24.png"  moduleUrl="plugins/appManager_001/AppManager_001.swf"  version="1.0"  date="2013-3-5"  author="way" type="plugin"  resizable="false"  description="對系統應用,及使用者自訂應用進行管理"  shortCutCreated="true"/>  <item name="導航設定"   icon="plugins/navigatorSetting_001/assets/icons/gears_48.png"   iconSmall="plugins/navigatorSetting_001/assets/icons/gears_24.png"   moduleUrl="plugins/navigatorSetting_001/NavigatorSetting_001.swf"  version="1.0"  date="2013-3-13" author="way" type="plugin" resizable="false"description="對導航進行設定"/>  <item name="主題設定"   icon="plugins/themeSetting_001/assets/icons/icon_48.png"   iconSmall="plugins/themeSetting_001/assets/icons/icon_24.png"   moduleUrl="plugins/themeSetting_001/ThemeSetting_001.swf"  version="1.0"  date="2013-3-5" author="way" type="plugin" resizable="false"  description="對系統的主題、樣式進行設定"/>    </apps>;     [Bindable]public var rawListShow:XML = null;  //搜尋過濾後的資料protected function init(event:FlexEvent):void{getData();}protected function textinput1_changeHandler(event:TextOperationEvent):void{getData();}//初始化資料private function getData():void{if(StringUtil.trim(textInput.text) == ""){rawListShow = rawList ;}else{createNewXml(textInput.text,rawList);}/* 開啟或關閉指定項目下的所有樹項目。如果設定 dataProvider 之後立即調用 expandChildrenOf(),則您可能看不到正確的行為。您應該等待對組件進行驗證或調用 validateNow() 方法 */tree1.validateNow();expandtree();}//搜尋過濾後,生產新的xmlprivate function createNewXml(searchString:String, xml:XML):void{rawListShow =<apps  name="應用程式" />;for(var i:int = 0; i<xml.children().length(); i++){var itemXml:XML = xml.child("item")[i];if(isInStr(searchString,itemXml.@name.toString())){   rawListShow.appendChild(itemXml);}}}//判斷search_str是否在str內 public function isInStr(search_str:String , str:String):Boolean{    var num:int= str.indexOf(search_str);if(num>-1){return true;}else{return false;}}//展開樹private function expandtree():void {for each(var item:XML in this.tree1.dataProvider)this.tree1.expandChildrenOf(item,true);}]]></fx:Script><fx:Declarations><!-- 該例子由waylau.com提供--></fx:Declarations><s:TextInput prompt="請輸入要搜尋的欄位"  x="10" y="10"  change="textinput1_changeHandler(event)" id="textInput"/><mx:Tree id="tree1" dataProvider="{rawListShow}"  labelField="@name" width="200" height="300" x="10" y="40"></mx:Tree><s:Label text="更多例子 請關注  waylau.com" x="10" y="360"/></s:Application>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.