【发布时间】:2024-05-03 13:21:41
【问题描述】:
在调试时,我确认状态正在改变,但单选按钮没有在视觉上更新。奇怪的交互:当我在状态更改后包含要执行的警报时,正确的单选按钮会成为活动选择,但一旦我退出警报,即使状态没有改变,它也会恢复。
constructor(props) {
super(props);
this.state = {
algorithmType: 'A*'
}
}
radioUpdated = (event) => {
this.setState({algorithmType: event.currentTarget.value});
}
<form>
<input type='radio'
id='PathFinding_RadioButton_Dijkstras'
name='algorithm'
value='Dijkstras'
checked={this.state.algorithmType == 'Dijkstras' && true}
onChange={this.radioUpdated}></input>
<label for="Dijkstras">Dijkstra's</label><br></br>
<input type='radio'
id='PathFinding_RadioButton_A*'
name='algorithm'
value='A*'
checked={this.state.algorithmType == 'A*'}
onChange={this.radioUpdated}></input>
<label for='A*'>A*</label><br></br>
<input type='radio'
id='PathFinding_RadioButton_D*'
name='algorithm'
value='D*'
onChange={this.radioUpdated}
checked={this.state.algorithmType == 'D*'}
></input>
<label for='D*'>D*</label>
</form>
【问题讨论】:
-
你的 sn-p 对我有用。组件还有更多内容吗?如果没有,你有哪个版本的
react和react-dom(检查你的package.json)?你用的是哪个浏览器?
标签: reactjs radio-button