/** * 调用的地方 */ var rootNode = btn.ownerCt.ownerCt.getRootNode(); // var rootNode = Ext.getCmp('deptmentTee').getRootNode(); var nodeList = traverseTree(rootNode); /** * Ext 遍历 tree 的所有节点 * @param node * @returns {} */ function traverseTree(node){ var n = {}; n.id = node.id; n.name = node.text; n.parentid = node.attributes.parentid; n.isleaf = (node.hasChildNodes()?0:1); n.type = node.attributes.type; if(node.isLeaf()){ } else { var cds = node.childNodes; var arr = []; for (var i=0; i<cds.length; i++) { arr.push(traverseTree(cds[i])); } n.children = arr; } return n; }