【发布时间】:2017-08-01 13:42:47
【问题描述】:
我正在尝试使用 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 不会 触发
使用字符串而不是整数也不能解决问题。我在这里做错了什么?谢谢!
【问题讨论】:
标签: javascript reactjs react-toolbox