扁平化后的树结构数组
interface MyTreeNode {
id: number;
name: string;
children?: MyTreeNode[];
}
const treeData: MyTreeNode[] = [
{
id: 1,
name: 'Node 1',
children: [
{
id: 2,
name: 'Node 2',
},
{
id: 3,
name: 'Node 3',
children: [
{
id: 4,
name: 'Node 4',
},
{
id: 5,
name: 'Node 5',
},
],
},
],
},
{
id: 6,
name: 'Node 6',
},
];
const flattenedData = flattenTreeArray(treeData);
扁平化树结构数组