1
我跟蹤生日,需要更改用戶輸入的狀態,但問題是我的生日數組的新實例是在用戶鍵入覆蓋狀態時創建的。任何想法如何改變生日指數狀態,即當他們進入月份位置0將改變,日期位置1將改變,年份位置3將改變。我如何改變我的狀態內的數組?
this.state = {
dob : ["", "", ""]
};
onInputChange(event) {
const type = event.target.name;
var dob = ["", "", ""];
if(type == "month") {
birthday[0] = event.target.value;
this.setState({ dob });
} else if(type == "date") {
birthday[1] = event.target.value;
this.setState({ dob });
} else if(type == "year"){
birthday[2] = event.target.value;
this.setState({ dob });
}
}
這是行不通的。這是發生了什麼https://puu.sh/uc7tq/e8646eab30.png – joethemow
更新我的答案與工作小提琴檢查:) –