Skip to content

Commit

Permalink
fix: 修复 Table 中调用 setData 报错问题 (baidu#9578)
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Feb 2, 2024
1 parent d6208f8 commit 6ef0248
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/amis-core/src/store/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ export const Item = types
reset() {
self.newIndex = self.index;
self.data = self.pristine;
},
updateData({children, ...rest}: any) {
self.data = {
...self.data,
...rest
};

// if (Array.isArray(children)) {

// }
}
}));

Expand Down
2 changes: 1 addition & 1 deletion packages/amis-core/src/store/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export const Row = types
self.loaded = false;
},

setDeferData({children, ...rest}: any) {
updateData({children, ...rest}: any) {
self.data = {
...self.data,
...rest
Expand Down
4 changes: 2 additions & 2 deletions packages/amis/src/renderers/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ export default class Table extends React.Component<TableProps, object> {
throw new Error(response.msg);
}

row.setDeferData(response.data);
row.updateData(response.data);
row.markLoaded(true);
row.setError('');
} catch (e) {
Expand Down Expand Up @@ -2888,7 +2888,6 @@ export class TableRenderer extends Table {
condition?: any
) {
const {store} = this.props;
const len = store.data.rows.length;

if (index !== undefined) {
let items = [...store.data.rows];
Expand All @@ -2901,6 +2900,7 @@ export class TableRenderer extends Table {
return store.updateData({rows: items}, undefined, replace);
} else if (condition !== undefined) {
let items = [...store.data.rows];
const len = items.length;
for (let i = 0; i < len; i++) {
const item = items[i];
const isUpdate = await evalExpressionWithConditionBuilder(
Expand Down

0 comments on commit 6ef0248

Please sign in to comment.