ztree 获取根节点

时间:2021-07-27 01:13:26

function getRoot() {
var treeObj = $.fn.zTree.getZTreeObj("tree-div");
//返回一个根节点
var node = treeObj.getNodesByFilter(function (node) { return node.level == 0 }, true);
}

function getRoots() {
var treeObj = $.fn.zTree.getZTreeObj("tree-div");
//返回根节点集合
var nodes = treeObj.getNodesByFilter(function (node) { return node.level == 0 });
}

//获取当前节点的根节点(treeNode为当前节点)
function getCurrentRoot(treeNode){
if(treeNode.getParentNode()!=null){
var parentNode = treeNode.getParentNode();
return getCurrentRoot(parentNode);
}else{
return treeNode.id;
}
}