---
title: "tree 打开节点"
author: "demojava"
date: "2011-12-19T22:40:17Z"
tags: []
categories: ["Web前端"]
slug: "tree"
draft: false
lastmod: "2011-12-19T22:40:17Z"
id: 1317207
url: "https://demojava.iteye.com/blog/1317207"
---

```
//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);
	//如果是模糊搜索可以用下面的代码
	//var xmllistDescendants:XMLList  = treeXml.descendants().(@name.toString().indexOf(nameStr)>-1);
	expandParents(xmllistDescendants[0]);
	myTree.selectedItem = xmllistDescendants[0];
}//findNodeById 
```

 转载连接：[http://yunzhongxia.iteye.com/blog/1258409](http://yunzhongxia.iteye.com/blog/1258409)