获得当前选中节点路径,如部门库〉新闻部〉文字稿:
树如下图:
js:
var curLocation="";//当前位置
var treeObj = $.fn.zTree.getZTreeObj("rs_tree");
var nodes = treeObj.getSelectedNodes();
if(nodes.length>0){
var allNode = nodes[0]['text'];//获取当前选中节点
var node = nodes[0].getParentNode();
getParentNodes(node,allNode);
}
var location = "";
var nodeArrs = curLocation.split(">");
for(var i=nodeArrs.length-1;i>=0;i--){
location += nodeArrs[i]+">";
}
location = location.substring(0, location.lastIndexOf(">"));
alert(location);
function getParentNodes(node,allNode){
if(node!=null){
allNode += ">"+node['text'];
curNode = node.getParentNode();
getParentNodes(curNode,allNode);
}else{
//根节点
curLocation = allNode;
}
}
结果:location: 部门库>政治部>国内