tree 实现搜索效果

<?xml version="1.0" encoding="utf-8"?>
<!-- Searchable Tree control example. uses e4x expression to find a node with matching id attribute-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">
<mx:Script><![CDATA[

  [Bindable]
  public var _xmlData:XML;
  
  public function initApp():void
  {
    _xmlData = <element eid="hello" name="a">
         <element eid="world" name="a1">
            <element eid="123" name="a1.1"/>
            <element eid="graham" name="a1.2"/>
            <element eid="weldon" name="a1.3">
               <element eid="office" name="a1.4">
                  <element eid="thing" name="a1.5"/>
                  <element eid="boat" name="a1.6"/>
                  <element eid="chair" name="a1.7"/>
                  <element eid="123" name="a1.8"/>
               </element>
               <element eid="person" name="a2.0"/>
                </element>
             </element>
             <element eid="123" name="a3.0"/>
          </element> ;
   trace("test")
  }//initapp
  
  //starts at the given node, walks up the tree opening nodes as it goes
  private function expandParents(xmlNode:XML):void
  {
    while (xmlNode.parent() != null) {  
      xmlNode = xmlNode.parent();
      myTree.expandItem(xmlNode,true, false);
    }
  }//expandParents

  //uses e4x to find a node, then calls expand parents to make it visible,
  //then selects it      
private function findNodeById(sId:String):void
{
  var xmllistDescendants:XMLList  = _xmlData.descendants().(@eid == sId);
  //expandParents(xmllistDescendants[0]);
  //myTree.selectedItem = xmllistDescendants[0];
  myTree.dataProvider = xmllistDescendants;
  }//findNodeById           
]]></mx:Script>

    <mx:Panel title="Tree Control Example" height="75%" width="75%" 
        paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
        <mx:HBox>
          <mx:TextInput id="tiId" text="boat" />
          <mx:Button label="Find" click="findNodeById(tiId.text)" />         
        </mx:HBox>
        <mx:Tree id="myTree" width="50%" height="100%" labelField="@name"
            showRoot="false" dataProvider="{_xmlData}" />      
    </mx:Panel>
</mx:Application>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值