easyui tree获取点击节点所在层次,easyui tree如何获取某个节点所在树层次源代码。easyui的节点没有存储所在层次,所有需要循环调用getParent方法获取父节点
函数:
//获取一个子结点的所有父结点
function getPath(node,id) {
var path = "";
path = node.text;
while (node = $(id).tree('getParent', node.target)) {
path = node.text + "\\" + path;
}
return path;
}
调用函数:
//调用
var path = "";
$("#Layer-tree").tree({ //#Layer-tree是指easyUI----tree---id
onCheck: function (node) {
if (node.checked) {
path = getPath(node, "#Layer-tree");
alert(path);
}
}
});
效果: