// 生成树形结构
// 生成树形结构
const makeTree = useCallback(
(
items: DeviceGroupInfo[],
id = null,
link: keyof DeviceGroupInfo = 'parentId'
): any => {
// const all = items.filter((item: DeviceGroupInfo) => item['parentId'] === id)
// console.log(all)
return items
.filter((item1: DeviceGroupInfo) => item1[link] === id)
.map((item: any) => {
console.log(item, "itemitem");
item.children = makeTree(items, item.id);
item.isLeaf = !item.children.length;
item.key = String(item.id)
if (!item.children.length) {
Reflect.deleteProperty(item, 'children');
}
return item;
});
},
[]
);