【发布时间】:2017-09-15 13:59:15
【问题描述】:
【问题讨论】:
-
您的查询有什么解决方案吗??
-
将rowKey参数传给表格组件
【问题讨论】:
这很简单。您将需要利用<Table /> 组件的expandedRowKeys 属性。该属性存储当前展开的行键的值。所以,我们要做的就是只设置当前展开的行键并删除其他的。
render()<Table
expandedRowKeys={this.state.expandedRowKeys}
onExpand={this.onTableRowExpand}
/>
onExpand回调onTableRowExpand(expanded, record){
var keys = [];
if(expanded){
keys.push(record.id); // I have set my record.id as row key. Check the documentation for more details.
}
this.setState({expandedRowKeys: keys});
}
更多阅读: <Table /> API Documentation
如果你使用钩子
// useState()
const [expandedRowKeys, setExpandedRowKeys] = useState([]);
render()<Table
expandedRowKeys={expandedRowKeys}
onExpand={onTableRowExpand}
/>
onExpand回调const onTableRowExpand = (expanded, record) => {
const keys = [];
if(expanded){
keys.push(record.id); // I have set my record.id as row key. Check the documentation for more details.
}
setExpandedRowKeys(keys);
}
【讨论】: