diff --git a/src/components/Table/src/hooks/useDataSource.ts b/src/components/Table/src/hooks/useDataSource.ts index 1a4d3aead..874ff602d 100644 --- a/src/components/Table/src/hooks/useDataSource.ts +++ b/src/components/Table/src/hooks/useDataSource.ts @@ -255,11 +255,8 @@ export function useDataSource( if (!api || !isFunction(api)) return; try { setLoading(true); - const { pageField, sizeField, listField, totalField } = Object.assign( - {}, - FETCH_SETTING, - fetchSetting, - ); + const { pageField, sizeField, listField, totalField, parentField, childrenField } = + Object.assign({}, FETCH_SETTING, fetchSetting); let pageParams: Recordable = {}; const { current = 1, pageSize = PAGE_SIZE } = unref(getPaginationInfo) as PaginationProps; @@ -295,7 +292,11 @@ export function useDataSource( const result = await api(params); const res = result.data; if (isTreeTable) { - const tree = array2tree(res.data); + const tree = array2tree(res.data, { + parentKey: parentField !== undefined && parentField !== '' ? parentField : 'parentId', + childrenKey: + childrenField !== undefined && childrenField !== '' ? childrenField : 'children', + }); rawDataSourceRef.value = tree; isArrayResult = Array.isArray(tree); resultItems = isArrayResult ? tree : get(tree, listField); diff --git a/src/components/Table/src/types/table.ts b/src/components/Table/src/types/table.ts index b6cb64950..aba6c6a62 100644 --- a/src/components/Table/src/types/table.ts +++ b/src/components/Table/src/types/table.ts @@ -132,6 +132,10 @@ export interface FetchSetting { listField: string; // 请求结果总数字段 支持 a.b.c totalField: string; + // 父级字段 + parentField: string; + // 子级字段 + childrenField: string; } export interface TableSetting {