猿问

Js问题,有一个jsonarray怎么转成多棵树?有没有好的方法

`[{

"id": "1","parentId": "0","nodeName": "公告资讯",

}, {

"id": "2","parentId": "1","nodeName": "查看公告",

}, {

"id": "4","parentId": "0","nodeName": "公告资讯",

}, {

"id": "5","parentId": "4","nodeName": "查看公告",

}, {

"id": "6","parentId": "4","nodeName": "查看公告1",

}]`
怎么转成
`[{

    "id": "1",    "parentId": "0",    "nodeName": "公告资讯",
    children: [{        "id": "2",        "parentId": "1",        "nodeName": "查看公告",
    }]
}, {    "id": "4",    "parentId": "0",    "nodeName": "公告资讯",
    children: [{        "id": "5",        "parentId": "4",        "nodeName": "查看公告",
    }, {        "id": "6",        "parentId": "4",        "nodeName": "查看公告1",
    }]
}`


蛊毒传说
浏览 496回答 1
1回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答