答案 0 :(得分:5)
您选择的代码中有错字:
<select className="text_15"> value={currentComponent.state.securityQuestion} onChange={(event) => this.saveQuestion(event)}>
<option value="0">What is you mother's maiden name?</option>
<option value="1">What elementary school did you attend?</option>
<option value="2">What was the name of your first pet?</option>
<option value="3">What city were you born in?</option>
</select>
应该是:
<select className="text_15" value={currentComponent.state.securityQuestion} onChange={(event) => this.saveQuestion(event)}>
<option value="0">What is you mother's maiden name?</option>
<option value="1">What elementary school did you attend?</option>
<option value="2">What was the name of your first pet?</option>
<option value="3">What city were you born in?</option>
</select>
您的select
标签上还有一个> 。
答案 1 :(得分:1)
您设置状态的方式正在丢失您以前的状态信息。
currentComponent.setState({ ...this.state,securityAnswer:localAnswer });
...this.state
被称为扩展,将保留您不想更改的状态元素。
答案 2 :(得分:0)
将函数绑定到this
,或使用箭头函数语法:
saveQuestion = (event) => {
let currentComponent = this;
var localQuestion = event.target.value;
console.log("localQuestion: ", localQuestion);
this.setState({securityQuestion: localQuestion});
}