this.state = {
listData: [
{name: "张三", age: "20"},
{name: "李四", age: "21"},
],
obj: {
name: "王五",
age: "22",
}
}
change = (index) => {
const listData = [...this.state.listData]; //复制数组--浅拷贝
const obj = Object.assign({}, this.state.obj, { age: "21" });
this.setState({
listData: listData.map((item, idx) => idx === index ? {...item, name: "赵六"} : item),
obj: obj,
})
}