鍍金池/ 問答/HTML/ 關(guān)于antd Radio單選框問題 react

關(guān)于antd Radio單選框問題 react

下面是用antd用的單選框,初始化它會根據(jù)接口請求回來的數(shù)據(jù)true或false來默認(rèn)勾選第幾個,如果初始化完了,我點(diǎn)擊查詢Button按鈕重新請求接口查到一些數(shù)據(jù)回來再次進(jìn)行setState到頁面上,變量名userNames是false或true就完全不起作用了,radio顯示的結(jié)果還是上一次初始化顯示的,不知道怎么回事

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} />
)
}
回答
編輯回答
青檸

你這個用法是不是有問題,應(yīng)該是在RadioGroup上傳value屬性,Radio不寫checked

2017年8月26日 18:05