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個贊
您設置狀態(tài)的方式將丟失您以前的狀態(tài)信息。
currentComponent.setState({ ...this.state,securityAnswer:localAnswer });
這...this.state
就是所謂的價差,它將保留您不想更改的狀態(tài)元素。

TA貢獻1796條經驗 獲得超10個贊
將函數(shù)綁定到this,或使用箭頭函數(shù)語法:
saveQuestion = (event) => {
let currentComponent = this;
var localQuestion = event.target.value;
console.log("localQuestion: ", localQuestion);
this.setState({securityQuestion: localQuestion});
}
添加回答
舉報