递归

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;
}

  

posted @ 2023-03-01 12:05  zjxgdq  阅读(4)  评论(0编辑  收藏  举报