实现一个函数fm,输入list,输出tree:const list = [ { id: '1', name: 'test1' }, { id: '11', name: 'test11' }, { id: '12', name: 'test12' }, { id: '111', name: 'test111' }, { id: '112', name: 'test112' }, { id: '121', name: 'test121' }, { id: '122', name: 'test122' } ]; const tree = [{ id: '1', name: 'test1', parentId: null, children: [ { id: '11', name: 'test11', parentId: '1', children: [{ id: '111', name: 'test111', parentId: '11', }, { id: '112', name: 'test112', parentId: '11', }] }, { id: '12', name: 'test12', parentId: '1', children:[{ id:'121', name:'test121', parentId:'12' },{ id:'122', name:'test122', parentId:'12' }] } ] }]
最新发布