我正在尝试使用 react-toolbox 单选按钮https://github.com/react-toolbox/react-toolbox/tree/dev/components/radio在我的反应应用程序中设置单选按钮。
这是我的代码:
import {RadioGroup, RadioButton} from 'react-toolbox/lib/radio';
class ClientsEdit extends Component {
constructor(props) {
super(props);
this.bindLibs();
this.state = {
counterType: 1
};
}
// Some other functions
render() {
return (
<div>
<RadioGroup name='counterType' value={this.state.counterType} onChange={this.handleRadioButtonChange}>
<RadioButton label={t('clients:new.numeric')} value={1}/>
<RadioButton label={t('clients:new.alphanumeric')} value={2}/>
</RadioGroup>
</div>
);
}
bindLibs= () => {
// ...
this.handleRadioButtonChange = handleRadioButtonChange.bind(this);
}
}
有两个问题:
- 尽管我声明
this.state.counterType
为 1,但未检查单选按钮 - 尝试更改状态(通过单击)时,不会触发 onChange
使用字符串而不是整数也不能解决问题。我在这里做错了什么?谢谢!