export function treeInit(down: any[]) { const treeData: { title: string; key: string; children: { title: string; key: string; }[]; }[] = []; let snap = 0; while (snap < down.length) { const { moduleName, parentId, moduleId } = down[snap]; treeData[snap] = { title: moduleName, key: parentId == '0' ? moduleId : parentId + '-' + moduleId, children: [] }; if (down[snap].sysPermModuleVOS.length > 0) treeData[snap].children = treeInit(down[snap].sysPermModuleVOS); snap++; } return treeData; }
标签:string,递归,title,treeData,down,snap,children From: https://www.cnblogs.com/zjxzhj/p/17167727.html