【发布时间】:2020-12-30 07:59:22
【问题描述】:
我正在创建一个锻炼日志应用程序,但在更新状态的嵌套属性时遇到了问题。这是我的状态...
this.state = {
chosenExercises: [
{
id: 1,
name: "Barbell Bench Press",
type: "Strength",
setCount: [1],
lbs: [],
reps: []
},
{
id: 2,
name: "Dumbell Bench Press",
type: "Strength",
setCount: [1],
lbs: [],
reps: []
}
]
} //End of state
//Function to update lbs from user input
updateLbs = (lbs) => {
//WHAT GOES HERE??
}
用户输入是 2 个组件,它是父组件中表单的一部分。是否可以使用作为 props 传递的父组件中的更改处理程序来更新每个练习的每组 lbs?
这是我在完成特定练习后正在寻找的结果。
this.state = {
chosenExercises: [
{
id: 1,
name: "Barbell Bench Press",
type: "Strength",
setCount: [1, 2, 3, 4],
lbs: [135, 135, 155, 185],
reps: [12, 12, 10, 8]
},
{
id: 2,
name: "Dumbell Bench Press",
type: "Strength",
setCount: [1],
lbs: [],
reps: []
}
]
}
我尝试将 .find() 和 .filter() 一起使用,但我还没有那么好。感谢您的帮助。
【问题讨论】: