fix: issue with adding data to sub-table after deletion

This commit is contained in:
katherinehhh 2024-11-02 22:03:51 +08:00
parent 0b762cf89f
commit a924a22a7c
2 changed files with 11 additions and 5 deletions

View File

@ -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')}

View File

@ -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);
});
}}
/>