我对 antd 可扩展表有问题
我有一张这样的桌子
<Table
loading={loading}
bordered
columns={columnslistdpa}
dataSource={dpalistnew.list}
style={{ minWidth: "960px" }}
locale={{
emptyText: "No data"
}}
pagination={false}
expandable={{
expandedRowRender: (record, index, indent, expanded) =>
renderExpandedRow(record, index, indent, expanded), //I render table again
onExpand: (state, record) => onExpandRow(record)
}}
/>;
const onExpandRow = (record) => {
getdpatapd(1, 10, record.idSkpd); //api function
};
在 onExpandRow 我调用我的 api 函数来设置状态
const getdpatapd = async (page, pageSize, idSkpd) => {
setLoading(true);
let res = [];
try {
res = await getdpaListTapd(params);
if (res.status === "200") {
setdpalisttapd(res.data); //I set state here
}
} catch (error) {
handleGlobalErrorFunc(error);
}
setLoading(false);
};
并且该状态用于数据源子表
const renderExpandedRow = (record, type, indent, expanded) => {
return (
<Table
className="table-sub-kegiatan table-yellow"
bordered
columns={columnslisttapd}
dataSource={dpalisttapd.list} // from state
pagination={false}
/>
)
}
当我展开第二行时,我得到 2 个数据
当我展开第一行时,我得到 1 个数据,但在第二行中更新为 1 个数据,因为数据源与状态相同
当我隐藏展开时,api总是点击.. T__T