From ee6cc5a66516addbdbca361fd02d51c7de395f49 Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 7 Jan 2021 09:25:27 +0800 Subject: [PATCH] fix: table section checkbox can not be selected --- .../form.fields/sub-table/Table.tsx | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/app/src/components/form.fields/sub-table/Table.tsx b/packages/app/src/components/form.fields/sub-table/Table.tsx index ed932ab6f..4c5f3fb62 100644 --- a/packages/app/src/components/form.fields/sub-table/Table.tsx +++ b/packages/app/src/components/form.fields/sub-table/Table.tsx @@ -42,17 +42,26 @@ export default function Table(props: SimpleTableProps) { resourceKey: 'simple' })); + const [dataSource, setDataSource] = useState(value.map((item, index) => { + if (item.__id) { + return item; + }; + return {...item, __id: generateIndex()}; + })) + if (loading) { return } + // console.log('dataSource', dataSource); return (
{ console.log({selectedRowKeys}) - const newValues = value.filter(item => selectedRowKeys.indexOf(item.__id) === -1); + const newValues = dataSource.filter(item => selectedRowKeys.indexOf(item.__id) === -1); + setDataSource(newValues); onChange(newValues); }}> @@ -67,32 +76,28 @@ export default function Table(props: SimpleTableProps) {
{ console.log(values); - const newVaules = [...value]; + const newVaules = [...dataSource]; if (typeof index === 'undefined') { newVaules.push({...values, __id: generateIndex()}) } else { newVaules[index] = values; } + setDataSource(newVaules); onChange(newVaules); - console.log(newVaules); + // console.log(newVaules); }} ref={drawerRef}/> { }} components={components({ data: { - list: value.map((item, index) => { - if (item.__id) { - return item; - }; - return {...item, __id: generateIndex()}; - }), + list: dataSource, }, mutate: (values) => { onChange(values.list);