treeData.data = setTreeData1(res.data.data.permissionList);
treeData.checkedKeys=[] //每次进来清空数据
treeData.oneTree=[]
// treeData.checkedKeys=checkedKeys.checkedKeys
nextTick(()=>{
let userMenuList:any=[]
if(res.data.data){
res.data.data.permissionList.forEach((item:any)=>{
if(item.havePermission==true){
userMenuList.push(item.permissionId)
treeData.oneTree.push(item.permissionId)
}
})
findAllChildren(treeData.data,userMenuList)
}
}
)
};
//userMenuList 所有选中的节点数据
//data 树结构
const findAllChildren=(data:any,userMenuList:any)=> {
let mainMenuList:any=[]
data.forEach((item:any, index:any) => {
if(item.children){
if(item.children.length !== 0) {
for (let i = 0; i < userMenuList.length; i++) {
if (item.permissionId == (userMenuList[i])) {
mainMenuList.push(userMenuList[i])
userMenuList.splice(i, 1);
}
}
findAllChildren(item.children,userMenuList);
}
}
})
treeData.checkedKeys=userMenuList
}
antd树形结构回显示递归判断子节点是否选中和删除父节点
最新推荐文章于 2024-05-17 10:25:36 发布