首页 > TAG信息列表 > mapItem

一维JSON转树结构

const treeFormat = (arr: any) => { let map: any = {}; // 构建map // 构建以id为键 当前数据为值 arr.forEach((item: any) => { item["children"] = []; map[item['id']] = item; }); const res: any = { data:[], other:[] };