数据的结构:
const nodeList=[
{id:1,name:树节点一",children:[{id:2,name:树节点二",children:[{id:3,name:树节点三"}]}]},
{id:4,name:树节点四"},
{id:5,name:树节点五",children:[{id:2,name:树节点二"}]},
]
写法:
<Tree defaultExpandAll checkable onCheck={this.onCheck}>
{this.setPermission(nodeList)}
</Tree>
setPermission =nodeList=>{
const children=[];
nodeList.forEach(item=>{
if(!item.children){
children.push(<TreeNode title={item.name} key={item.id}/>)
}else{
children.push(
children.push(
<TreeNode title={item.name} key={item.id}>
{this.setPermission(item.children)}
</TreeNode>)
)
}
})
return children;
}
当要获取父节点的时候
onCheck=(checkedKeys,info)=>{
//选中的节点 checkedKeys
//选中子节点的父节点 info.halfCheckedKeys
}