【发布时间】:2021-07-07 20:12:48
【问题描述】:
我有一个对象数组,每个对象都有这些值
id: "53ed5e27-23a5-4a06-b53f-d0113d607fb5"
measure:
units: Array(2)
0: {perPortion: 15, name: "tbsp"}
1: {perPortion: 1, name: "ml"}
我正在遍历数组并将点击函数传递给按钮。
function handleClick(index: number, ingredient: Data) {
//copy original array
const newListArr = [...props.data];
newListArr[index] = {
...newListArr[index],
}
}
函数获取点击对象的索引。我正在复制循环数组,然后尝试使用扩展运算符来引入所有属性。
我的问题是我不知道如何对嵌套对象使用扩展运算符。
我只想获取单位数组中“perPortion”键的值而不影响其他任何内容。 我该怎么做?
提前感谢您的帮助!
【问题讨论】:
标签: reactjs