From b40e6104b08962d03536c7493e2fe05a6d58e98b Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Fri, 1 Dec 2023 18:09:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20inputTable=20?= =?UTF-8?q?=E5=9C=A8=E5=88=97=E4=B8=AD=E8=A1=A8=E5=8D=95=E9=A1=B9=E6=9C=89?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=80=BC=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=96=B0=E5=A2=9E=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#8989)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis/src/renderers/Form/InputTable.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/amis/src/renderers/Form/InputTable.tsx b/packages/amis/src/renderers/Form/InputTable.tsx index 6fc59d8680d..d5242b1b3d8 100644 --- a/packages/amis/src/renderers/Form/InputTable.tsx +++ b/packages/amis/src/renderers/Form/InputTable.tsx @@ -685,7 +685,20 @@ export default class FormTable extends React.Component { this.setState( { - items + items, + // 需要一起修改,state 不能分批次 setState + // 因为第一步添加成员,单元格的表单项如果有默认值就会触发 onChange + // 然后 handleTableSave 里面就会执行,因为没有 editIndex 会以为是批量更新 state 后 emitValue + // 而 emitValue 又会干掉 __isPlaceholder 后 onChange 出去一个新数组,空数组 + // 然后 didUpdate 里面检测到上层 value 变化了,又重置 state,导致新增无效 + // 所以这里直接让 items 和 editIndex 一起调整,这样 handleTableSave 发现有 editIndex 会走不同逻辑,不会触发 emitValue + ...((needConfirm === false + ? {} + : { + editIndex: index, + isCreateMode: true, + columns: this.buildColumns(this.props, true, index) + }) as any) }, async () => { if (isDispatch) { @@ -696,8 +709,6 @@ export default class FormTable extends React.Component { } if (needConfirm === false) { this.emitValue(); - } else { - this.startEdit(index, true); } } );