Skip to content

Commit

Permalink
fix(amis): list嵌套在crud下面,setValue时通过crud进行操作,解决crud的setValue动作失效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ranwawa committed Jan 9, 2025
1 parent 6b1b310 commit dbd82e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 11 additions & 1 deletion packages/amis/__tests__/renderers/CRUD.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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();
});
});
11 changes: 8 additions & 3 deletions packages/amis/src/renderers/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IItem>(
Expand All @@ -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() {
Expand Down

0 comments on commit dbd82e9

Please sign in to comment.