ztree 获取根节点

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; 

}

 

 

 

--------------摘自雍老师博客--------------

转载于:https://www.cnblogs.com/sword082419/p/9399970.html

你可能感兴趣的:(ztree 获取根节点)