把一个正常的tree数据处理一下, data是一个树形结构数据,需要给data做处理把相关节点移位,结合下面的例子找出规律并封装好一个处理的函数 目的:这样做是为了渲染tree的试试不用那么多层节点 例子1: let data=[{ "name": "发起", "children": [ { "name": "莫二", "children":[] } ], }] 处理后的结果 result=[ { "name": "发起", "children":[] }, { "name": "莫二", "children":[] } ] 例子2: let data=[{ "name": "发起", "children": [ { "name": "市场部", "children": [ { "name": "总经理", "children": [], } ], }, { "name": "财务部", "children": [ { "name": "总经理", "children": [], } ], } ], }] 预期返回 data=[{ "name": "发起", "children": [ { "name": "市场部", "children": [ { "name": "总经理", "children": [], } ], }, { "name": "财务部", "children": [ { "name": "总经理", "children": [], } ], } ], }] 例子3: // let data=[{ "name": "发起", "children": [ { "name": "市场部", "children": [ { "name": "总经理", "children": [ { "name": "董事长", "children": [], } ], } ], }, { "name": "财务部", "children": [ { "name": "总经理", "children": [ { "name": "董事长", "children": [], } ], } ], } ], }] 预期返回 data=[{ "name": "发起", "children": [ { "name": "市场部", "children": [ { "name": "总经理", "children": [], }, { "name": "董事长", "children": [], } ], }, { "name": "财务部", "children": [ { "name": "总经理", "children": [], },{ "name": "董事长", "children": [], } ], } ], }]