ztree中获取选中节点下的所有叶子节点
var setting = {
data: {
simpleData: {
enable: true
}
},
callback: {
onClick: treenodeClick
}
};
//点击树节点,获取节点的所有叶子节点id
function treenodeClick(event, treeId, treeNode, clickFlag) {
//此处treeNode 为当前节点
var str =‘‘ ;
if(treeNode.isParent){
str = getAllChildrenNodes(treeNode,str);
}else{
str=treeNode.id;
}
alert(str); //所有叶子节点ID
}
//使用了递归,得到叶子节点的数据
function getAllChildrenNodes(treeNode,result){
if (treeNode.isParent) {
var childrenNodes = treeNode.children;
if (childrenNodes) {
for (var i = 0; i < childrenNodes.length; i++) {
if(childrenNodes[i].isParent){
result = getAllChildrenNodes(childrenNodes[i], result);
}else{
result += ‘,‘ + childrenNodes[i].id;
}
}
}
}
return result;
}