From dbd82e96144ed756187ccaa50f6ed1a8de6d0c15 Mon Sep 17 00:00:00 2001 From: ranqirong <274544338@qq.com> Date: Thu, 9 Jan 2025 10:37:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(amis):=20list=E5=B5=8C=E5=A5=97=E5=9C=A8cru?= =?UTF-8?q?d=E4=B8=8B=E9=9D=A2=EF=BC=8CsetValue=E6=97=B6=E9=80=9A=E8=BF=87?= =?UTF-8?q?crud=E8=BF=9B=E8=A1=8C=E6=93=8D=E4=BD=9C=EF=BC=8C=E8=A7=A3?= =?UTF-8?q?=E5=86=B3crud=E7=9A=84setValue=E5=8A=A8=E4=BD=9C=E5=A4=B1?= =?UTF-8?q?=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis/__tests__/renderers/CRUD.test.tsx | 12 +++++++++++- packages/amis/src/renderers/List.tsx | 11 ++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/amis/__tests__/renderers/CRUD.test.tsx b/packages/amis/__tests__/renderers/CRUD.test.tsx index 51e3184a10d..c6a7046869a 100644 --- a/packages/amis/__tests__/renderers/CRUD.test.tsx +++ b/packages/amis/__tests__/renderers/CRUD.test.tsx @@ -1897,7 +1897,7 @@ test('25. CRUD Table Cell sync data to store', async () => { expect(listDoms2.length).toEqual(0); }); -describe.only('26. setValue 动作', () => { +describe('26. setValue 动作', () => { const renderCrud = (mode: string) => render( amisRender({ @@ -1952,4 +1952,14 @@ describe.only('26. setValue 动作', () => { expect(screen.getByText('点击后')).toBeInTheDocument(); }); + + it('list模式下,设置值后,页面能够自动更新', () => { + renderCrud('list'); + + expect(screen.getByText('点击前')).toBeInTheDocument(); + + fireEvent.click(screen.getByText('点击前')); + + expect(screen.getByText('点击后')).toBeInTheDocument(); + }); }); diff --git a/packages/amis/src/renderers/List.tsx b/packages/amis/src/renderers/List.tsx index 02d02c952f7..a7a8beaa4c9 100644 --- a/packages/amis/src/renderers/List.tsx +++ b/packages/amis/src/renderers/List.tsx @@ -1173,7 +1173,7 @@ export class ListRenderer extends List { index?: number | string, condition?: any ) { - const {store} = this.props; + const {store, host} = this.props; if (index !== undefined || condition !== undefined) { const targets = await getMatchedEventTargets( @@ -1185,9 +1185,14 @@ export class ListRenderer extends List { targets.forEach(target => { target.updateData(values); }); - } else { - return store.updateData(values, undefined, replace); + return; } + + if (host) { + host.setData?.(values, replace); + } + + return store.updateData(values, undefined, replace); } getData() {