From 14f843ef7969e8850edf3ac913dd83bca717d0ee Mon Sep 17 00:00:00 2001 From: Katherine Date: Sat, 2 Nov 2024 22:09:36 +0800 Subject: [PATCH] fix: issue with adding data to sub-table after deletion (#5568) --- .../antd/association-field/SubTable.tsx | 3 ++- .../src/schema-component/antd/table-v2/Table.tsx | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx b/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx index 0c512ac01b..0abb554a1d 100644 --- a/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx @@ -165,7 +165,7 @@ export const SubTable: any = observer( }; const getFilter = () => { const targetKey = collectionField?.targetKey || 'id'; - const list = (field.value || []).map((option) => option[targetKey]).filter(Boolean); + const list = (field.value || []).map((option) => option?.[targetKey]).filter(Boolean); const filter = list.length ? { $and: [{ [`${targetKey}.$ne`]: list }] } : {}; return filter; }; @@ -235,6 +235,7 @@ export const SubTable: any = observer( // 计算总页数,并跳转到最后一页 const totalPages = Math.ceil(field.value.length / (field.componentProps?.pageSize || 10)); setCurrentPage(totalPages); + return field.onInput(field.value); }} > {t('Add new')} diff --git a/packages/core/client/src/schema-component/antd/table-v2/Table.tsx b/packages/core/client/src/schema-component/antd/table-v2/Table.tsx index bbde2d43c7..e7d29e84b6 100644 --- a/packages/core/client/src/schema-component/antd/table-v2/Table.tsx +++ b/packages/core/client/src/schema-component/antd/table-v2/Table.tsx @@ -191,10 +191,15 @@ const useTableColumns = (props: { showDel?: any; isSubTable?: boolean }, paginat onClick={() => { return action(() => { const fieldIndex = (current - 1) * pageSize + index; - const updatedValue = [...field.value]; - updatedValue.splice(fieldIndex, 1); - field.value = updatedValue; - field.onInput(field.value); + spliceArrayState(field, { + startIndex: fieldIndex, + deleteCount: 1, + }); + field.value.splice(fieldIndex, 1); + setTimeout(() => { + field.value[field.value.length] = null; + }); + return field.onInput(field.value); }); }} />