下面我们利用场景和实现方案。在此还是感谢小伙伴们的阅读、关注、点赞、转发。
let menuData = [
{
id: 1,
path: '/urlA',
title: '一级A',
children: [
{pid: 1, id: 11, path: 'urlAA', title: '二级A'},
{pid: 1, id: 12, path: 'urlBB', title: '二级B'}
]
},
{
id: 2,
path: '/urlB',
title: '一级B',
children: [
{pid: 2, id: 21, path: 'urlCC', title: '二级C'},
{pid: 2, id: 22, path: 'urlDD', title: '二级D'}
]
}
]
let arr = [];
for (let index = 0; index < menuData.length; index ) {
let childData = menuData[index].children;
let child = [];
for(let key = 0 ; key < childData.length; key ){
child.push({pid: childData[key].pid, id: childData[key].id,name: childData[key].title});
}
arr.push({id: menuData[index].id,name: menuData[index].title,child: child})
}
console.log(arr)
输出结果如图:
,Copyright © 2008-2022 秒下下载站
m.down10s.com .All Rights Reserved