3 回答
TA贡献1871条经验 获得超13个赞
您选择的代码中有错字:
<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。
TA贡献1848条经验 获得超10个赞
您设置状态的方式将丢失您以前的状态信息。
currentComponent.setState({ ...this.state,securityAnswer:localAnswer });
这...this.state
就是所谓的价差,它将保留您不想更改的状态元素。
TA贡献1796条经验 获得超10个赞
将函数绑定到this,或使用箭头函数语法:
saveQuestion = (event) => {
let currentComponent = this;
var localQuestion = event.target.value;
console.log("localQuestion: ", localQuestion);
this.setState({securityQuestion: localQuestion});
}
添加回答
举报