mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 06:35:20 +00:00
fix: issue with adding data to sub-table after deletion (#5568)
This commit is contained in:
parent
0b762cf89f
commit
14f843ef79
@ -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')}
|
||||
|
@ -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);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user