fix: issue with adding data to sub-table after deletion (#5568)

This commit is contained in:
Katherine 2024-11-02 22:09:36 +08:00 committed by GitHub
parent 0b762cf89f
commit 14f843ef79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View File

@ -165,7 +165,7 @@ export const SubTable: any = observer(
}; };
const getFilter = () => { const getFilter = () => {
const targetKey = collectionField?.targetKey || 'id'; 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 }] } : {}; const filter = list.length ? { $and: [{ [`${targetKey}.$ne`]: list }] } : {};
return filter; return filter;
}; };
@ -235,6 +235,7 @@ export const SubTable: any = observer(
// 计算总页数,并跳转到最后一页 // 计算总页数,并跳转到最后一页
const totalPages = Math.ceil(field.value.length / (field.componentProps?.pageSize || 10)); const totalPages = Math.ceil(field.value.length / (field.componentProps?.pageSize || 10));
setCurrentPage(totalPages); setCurrentPage(totalPages);
return field.onInput(field.value);
}} }}
> >
{t('Add new')} {t('Add new')}

View File

@ -191,10 +191,15 @@ const useTableColumns = (props: { showDel?: any; isSubTable?: boolean }, paginat
onClick={() => { onClick={() => {
return action(() => { return action(() => {
const fieldIndex = (current - 1) * pageSize + index; const fieldIndex = (current - 1) * pageSize + index;
const updatedValue = [...field.value]; spliceArrayState(field, {
updatedValue.splice(fieldIndex, 1); startIndex: fieldIndex,
field.value = updatedValue; deleteCount: 1,
field.onInput(field.value); });
field.value.splice(fieldIndex, 1);
setTimeout(() => {
field.value[field.value.length] = null;
});
return field.onInput(field.value);
}); });
}} }}
/> />