这是我的阵列。我只是想用祖父母->父母->孩子姓名关系构建一个层次结构树。请帮我解决这个问题。示例输入如下所示
data = [ {name:'111',parent:'11',grandparent:'1'}, {name:'112',parent:'11',grandparent:'1'}, {name:'121',parent:'12',grandparent:'1'}, {name:'211',parent:'21',grandparent:'2'} ]
预期输出是这样的。如有语法错误请忽略
[
{
name:'1',
children:[
{
name:'11',
children:[
{
name:'111',
children:[]
},
{
name:'112',
children:[]
}
]
},
{
name:'12',
children:[
{
name:'121',
children:[]
}
]
},
{
name:'21',
children:[
{
name:'211',
children:[]
}
]
}
]
}
]
阿晨1998
肥皂起泡泡
相关分类