下面是用antd用的单选框,初始化它会根据接口请求回来的数据true或false来默认勾选第几个,如果初始化完了,我点击查询Button按钮重新请求接口查到一些数据回来再次进行setState到页面上,变量名userNames是false或true就完全不起作用了,radio显示的结果还是上一次初始化显示的,不知道怎么回事
render() {
const data = this.state.PartDatas;
........
const columns = [
.........
{
title: '投票',
render: (text, data, index) => {
const userName = text.STATE;
return(
<RadioGroup onChange={this.onChange}>
<Radio checked={ userNames === "A" ? true : false } value="0">A</Radio>
<Radio checked={ userNames === "B" ? true : false } value="1">B</Radio>
<Radio checked={ userNames === "C" ? true : false } value="2">C</Radio>
</RadioGroup>
);
}
}]
return (
<Table scroll={{ x: true, y: 500 }} onRowClick={this.fAnalysis} pagination={false} columns={columns} dataSource={data} onChange={this.handleChange} />
)
}
你这个用法是不是有问题,应该是在RadioGroup上传value属性,Radio不写checked