我想将这个json/object转换为下面的特定结构,以便我可以使用treeList组件。
我尝试构建了一个递归函数,但是我还没有找到解决方案。谢谢你的帮助。
我尝试构建了一个递归函数,但是我还没有找到解决方案。谢谢你的帮助。
const data = {
parent1: {
child1: { bar: "1" },
child2: "2"
},
parent2: {
child1: "1"
}
}
to
const treeData = [
{
title: "parent1",
key: "parent1",
children: [
{
title: "child1",
key: "child1",
children: [{ title: "bar", key: "bar", value: "1" }]
},
{
title: "child2",
key: "child2",
value: "2"
}
],
},
{
title: "parent2",
key: "parent2",
children: [
{
title: "child1",
key: "child1",
value: "1"
}
]
}
]