fix 修复树形结果转换函数

This commit is contained in:
yxh 2023-04-13 21:16:09 +08:00
parent de14eaf7b5
commit 232e578a6b

View File

@ -29,7 +29,7 @@ export function getUpFileUrl(url:string){
* @param {*} children 'children'
* @param {*} rootId Id 0
*/
export function handleTree(data:any[], id:string, parentId:string, children:string, rootId:number):any[] {
export function handleTree(data:any[], id:string, parentId:string, children:string, rootId:any):any[] {
id = id || 'id'
parentId = parentId || 'parentId'
children = children || 'children'
@ -44,7 +44,16 @@ export function handleTree(data:any[], id:string, parentId:string, children:stri
});
branchArr.length > 0 ? father[children] = branchArr : '';
//返回第一层
return father[parentId] === rootId;
switch (typeof father[parentId]){
case 'string':
if(father[parentId]===''&&rootId===0){
return true
}
return father[parentId]===rootId.toString();
case 'number':
return father[parentId] === rootId;
}
return false;
});
return treeData != '' ? treeData : data;
}