//tree 是个Ext.tree.TreePanel对象
var
roonodes = tree.getRootNode().childNodes;
//获取主节点
findchildnode(roonodes);
//开始递归
function
findchildnode(node){
var
childnodes = node.childNodes;
for
(
var
i=0;i<childnodes.length;i++){
//从节点中取出子节点依次遍历
var
rootnode = roonodes[i];
alert(rootnode.text);
if
(rootnode.childNodes.length>0){
//判断子节点下是否存在子节点,个人觉得判断是否leaf不太合理,因为有时候不是leaf的节点也可能没有子节点
findchildnode(rootnode);
//如果存在子节点 递归
}
}
}
/**!
* 取得某个节点下所有的父节点
*
*/
getAllParents: function (node) {
var parentNodes = [];
parentNodes.push(node);
if (node.parentNode) {
parentNodes = parentNodes.concat(this.getAllParents(node.parentNode));
}
return parentNodes;
},
///**
// * 当点击子节点时 将父节点选中
// **/
checkedParentNodesWhenCheckChild:function (node) {
var tree=node.getOwnerTree();
tree.suspendEvents();
var allParentNodes = this.getAllParents(node);
if (allParentNodes.length > 1) {
for ( var i = 0; i < allParentNodes.length; i++) {
if (allParentNodes[i].id != node.id) {
if (!allParentNodes[i].getUI().isChecked()) {
allParentNodes[i].getUI().toggleCheck();
}
}
}
}
tree.resumeEvents();
},
* 取得某个节点下所有的父节点
*
*/
getAllParents: function (node) {
var parentNodes = [];
parentNodes.push(node);
if (node.parentNode) {
parentNodes = parentNodes.concat(this.getAllParents(node.parentNode));
}
return parentNodes;
},
///**
// * 当点击子节点时 将父节点选中
// **/
checkedParentNodesWhenCheckChild:function (node) {
var tree=node.getOwnerTree();
tree.suspendEvents();
var allParentNodes = this.getAllParents(node);
if (allParentNodes.length > 1) {
for ( var i = 0; i < allParentNodes.length; i++) {
if (allParentNodes[i].id != node.id) {
if (!allParentNodes[i].getUI().isChecked()) {
allParentNodes[i].getUI().toggleCheck();
}
}
}
}
tree.resumeEvents();
},