标签:
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