【发布时间】:2017-11-05 12:22:26
【问题描述】:
我无法让“checked”属性在 React 中的单选按钮上工作。请注意,当我单击单选按钮时,类属性正确更新为“已选择”,因此“activeRating.time_felt_right === false”检查正在工作。
<input type="radio" value="false"
id={`time_felt_right_${activeRating.id}_false`}
checked={activeRating.time_felt_right === false}
className={activeRating.time_felt_right === false ? 'selected' : null}
onChange={e => {
console.log('false');
e.preventDefault()
updateActiveRating({ time_felt_right: false })
}
}
/>
activeRating 由 Redux 的 mapStateToProps 提供。 updateActiveRating 定义如下:
const mapDipsatchToProps = (dispatch) => ({
updateActiveRating (rating) {
dispatch(updateActiveRatingAction(rating));
},
});
【问题讨论】:
-
尝试为复选框提供“名称”属性
-
感谢@DayanMorenoLeon 的想法。我添加了一个名字,但它仍然不起作用。
-
activeRating是什么,updateActiveRating的来源是什么?请添加所有相关代码 -
谢谢@AndyRay。更新了!
-
e.preventDefault()可能是罪魁祸首...尝试删除那个
标签: reactjs