zTree获取子节点

1 var ids=[];
2 ids=getChildren(ids, treeNode);//TreeNode是选中节点,ids是子节点id数组,格式:123,223,4,55

1.获取直接子节点的id

//返回值包含选中节点的id,即ids[0]
function getChildren(ids, treeNode) {
   ids.push(treeNode.id);//选中节点id,即父节点id
   if (treeNode.isParent) {
       for (var obj in treeNode.children) {
            getChildren(ids, treeNode.children[obj]);
       }
   }
   return ids;
}

2.获取全部子节点id

 1 //返回值是否包含选中节点id,根据情况而定
 2 function getChildren(ids, treeNode) {
 3    ids.push(treeNode.id);//选中节点id,即父节点id
 4    if (treeNode.isParent) {
 5        for (var obj in treeNode.children) {
 6             ids.push(treeNode.children[obj].id);
 7        }
 8    }
 9    return ids;
10 }

 

文章来自:http://www.cnblogs.com/wanshi1989/p/4240067.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3