读书人

搜寻tree并打开节点

发布时间: 2012-08-27 21:21:57 作者: rapoo

搜索tree并打开节点

??????? tree如果节点比较多的时候查找一个节点很费事,因此需要在树的上面添加一个模糊搜索框,当文本的内容发生变化的时候,自动搜索树并打开选中相应的节点。

?

?????? 代码如下:

?

??????

//starts at the given node, walks up the tree opening nodes as it goesprivate 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);//如果是模糊搜索可以用下面的代码//var xmllistDescendants:XMLList  = treeXml.descendants().(@name.toString().indexOf(nameStr)>-1);expandParents(xmllistDescendants[0]);myTree.selectedItem = xmllistDescendants[0];}//findNodeById 

?

?

?

?

读书人网 >Web前端

热点推荐