Now we have the following data structure:
[{
id: 1,
pid: 0,
name: "年级"
}, {
id: 2,
pid: 1,
name: "一年级"
}, {
id: 3,
pid: 1,
name: "二年级"
}, {
id: 4,
pid: 0,
name: "专业"
}, {
id: 5,
pid: 4,
name: "单片机开发"
}]
Write a JS method to convert it into the following format data:
[{
id: 1,
pid: 0,
name: "年级",
children: [{
id: 2,
pid: 1,
name: "一年级"
}, {
id: 3,
pid: 1,
name: "二年级"
}]
}, {
id: 4,
pid: 0,
name: "专业",
children: [{
id: 5,
pid: 4,
name: "单片机开发"
}]
}]
Please refer to it