Wie konvertiert man diese beiden Datenformate über JS ineinander?
Derselbe Inhalt, die flachen werden zu verschachtelten Formaten zusammengefasst und die verschachtelten werden in flache Formate zerlegt
Ich konnte es nach langer Zeit nicht mehr herausfinden, bitte helfen Sie!
[
{
"id":1,
"number":"100.000",
"name": "admin.",
"level":1,
"children": [
{
"id": 2,
"number": "100.210",
"name": "admin.marketing",
"level": 2
},
{
"id": 3,
"number": "100.260",
"name": "admin.operation",
"level": 2,
"children": [
{
"id": 5,
"number": "260.261",
"name": "operation.content",
"level": 3
},
{
"id": 6,
"number": "260.262",
"name": "operation.promote",
"level": 2
},
{
"id": 7,
"number": "260.263",
"name": "operation.service",
"level": 2
}
]
},
{
"id": 4,
"number": "100.280",
"name": "admin.development",
"level": 2
}
]
}
]
[
{
"id":1,
"number":"100.000",
"name": "admin.",
"level":1
},
{
"id": 2,
"number": "100.210",
"name": "admin.marketing",
"level": 2
},
{
"id": 3,
"number": "100.260",
"name": "admin.operation",
"level": 2
},
{
"id": 4,
"number": "100.280",
"name": "admin.development",
"level": 2
},
{
"id": 5,
"number": "260.261",
"name": "operation.content",
"level": 3
},
{
"id": 6,
"number": "260.262",
"name": "operation.promote",
"level": 3
},
{
"id": 7,
"number": "260.263",
"name": "operation.service",
"level": 3
}
]
利用递归实现
最外面的data是数组,其实他可以被认为是外层的 children 属性,而data的子元素自己也说不定有 children。
现在逆向的方法也在群友owl的帮助下完成了!