原文同步至: 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();
}
//搜索过滤后,生产新的xml
private 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>
分享到:
相关推荐
我见到过的最好用的flex4 chm api,非常完整,超级帮 最新Flex4.6中文API,离线帮助文档,无js错误
Flex4.6+Hibernate+spring配置好了的 拿去后导入直接使用
flex4.6文档与java结合,java,xml
之前学习flex4.6时下载的flex4.6API帮助,打开太过缓了。经过我的优化,现在查询起来速度非常快。希望各位喜欢。
flex api文档 4.6 的 用谷歌打开
Adobe® Flex® Software Development Kit (SDK) includes the Flex framework (component class library) and Flex compiler, enabling you to freely develop and deploy Flex applications using an IDE of your ...
Flash Builder 4.6(flex4.6)破解方式
这个文件是我根据http://download.csdn.net/detail/ptw19850409/1994130这个代码修改出来的,这段代码里面很多东西都是在旧版本的flash builder上面写的,我把它改成在flash builder4.6上能用的 所以代码的所有权...
详细讲解FLEX4.6+myeclipse9的安装过程。 常见的一些环境问题都有具体说明。 里面有惊喜哦!
上接第一部分。之前下载过的flex4.6的语言参考打开过于缓慢,我简单的优化了一下。
搭配flex4.6+blaze+java开发环境所用的jar包。
Flex4.6可用,包含多种特效,例子可网上查询。
Flex 4.6 仪表盘实例。是一个很好的视频教程,里面包含两个视频。
flex前端技术,对应版本4.6 api文档,chm格式版文档,方便搜索查看,作为工具类文档,随用随查
As puremvc 实例,代码是flex4.6平台的,找了很多资料都是以前的代码用不起来,这个是新的,没怎么用自带的组件,初学者可以看看怎么回事。
flex4.6 可以拉伸的TitleWindow。自由缩放。
flex 4.6 api帮助文档 用谷歌打开
对刚接触flex的朋友很有帮助,初步了解flex的相关知识,非常有用
本人在整合flex+spring遇到些问题.最后还是解决了.现提供demo代码供大家参考.eclipse3.7 + flex4.6 + spring3.0.6 注解方式.