fix: customized create action supports tree data for table selection data (#2328)
* fix: customized add action in table selection data supports tree data * fix: customized add action in table selection data supports tree data
This commit is contained in:
parent
43a75fe599
commit
c7a30c314c
@ -13,11 +13,23 @@ type VariablesCtx = {
|
||||
$form?: Record<string, any>;
|
||||
};
|
||||
|
||||
function flattenDeep(data, result = []) {
|
||||
for (let i = 0; i < data?.length; i++) {
|
||||
const { children, ...rest } = data[i];
|
||||
result.push(rest);
|
||||
if (children) {
|
||||
flattenDeep(children, result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export const useVariablesCtx = (): VariablesCtx => {
|
||||
const currentUser = useCurrentUserContext();
|
||||
const { field, service, rowKey } = useTableBlockContext();
|
||||
const contextData = service?.data?.data?.filter((v) => (field?.data?.selectedRowKeys || [])?.includes(v[rowKey]));
|
||||
const tableData = flattenDeep(service?.data?.data);
|
||||
return useMemo(() => {
|
||||
const contextData = tableData?.filter((v) => (field?.data?.selectedRowKeys || [])?.includes(v[rowKey]));
|
||||
return {
|
||||
$user: currentUser?.data?.data || {},
|
||||
$date: {
|
||||
|
Loading…
Reference in New Issue
Block a user