下面的数据多层树状结构怎么处理成,只有一层children的结构,谢谢
data = [
{
name: "About",
path: "/about",
children: [
{
name: "About US",
path: "/about/us"
},
{
name: "About Comp",
path: "/about/company",
children: [
{
name: "About Comp A",
path: "/about/company/A",
children: [
{
name: "About Comp A 1",
path: "/about/company/A/1"
}
]
}
]
}
]
}
]
// 处理后的结构
[
{
name: "About",
path: "/about",
children: [
{
name: "About US",
path: "/about/us"
},
{
name: "About Comp",
path: "/about/company",
},
{
name: "About Comp A",
path: "/about/company/A"
},
{
name: "About Comp A 1",
path: "/about/company/A/1"
}
]
}
]
写了一个可自由定义扁平化层级的代码,level代码不扁平的层级