【发布时间】:2016-08-05 03:44:10
【问题描述】:
当用户单击我的 react-js 代码更新单选按钮(或文本输入字段)时,我正在努力获取它们。先上代码(略略):
// (...)
@connect(mapStateToProps, mapDispatchToProps)
export default class EditMatch extends React.Component {
render() {
return (
<div>
<form>
<input
type="radio"
name="ms"
value="isPlayed"
checked={props.matchStatus === "isPlayed"}
onChange={this.stateChange}
/>
Not played
<input
type="radio"
name="ms"
value="played"
checked={props.matchStatus === "played"}
onChange={this.stateChange}
/>
Played
</form>
</div>
);
}
stateChange(e) {
console.log(e.currentTarget);
console.log(this.props);
}
}
控制台输出为:
<input type="radio" name="matchStatus" value="p2walkover" data-reactid=".109bqx8vjeo.0.0.1.3.1.2.0.1.2.0.7">
edit-match.js?6505:71 Uncaught TypeError: Cannot read property 'props' of undefined
所以基本上'this'是未定义的。所以我无法关注this pattern 并致电this.setState。
我做错了什么?
【问题讨论】: