我在react redux状态的初始值基本上是从API获取的。在data
中let data = {
item: [],
name: "random",
description: "hello",
status: "true",
asset: [],
version: "0.043",
}
现在我想用
下面的项数组替换数据中的项数组[]let item = [
{
item:
{
name: "random",
description: "General Description",
status: "true",
asset: [],
version: "0.043",
},
quantity: "344"
},
{
item: {
name: "random",
description: "General Description",
status: "true",
asset: [],
version: "0.043"
},
quantity: "434"
}
]
我想要实现的是更新react redux状态,然后将其发布到Api
data = {
item: [
{
item: {
name: "random",
descr: "General Descr",
status: "true",
asset: [],
version: "0.043",
},
quantity: "344"
},
{
item: {
name: "random",
descr: "General Descr",
status: "true",
asset: [],
version: "0.043",
},
quantity: "344"
}
],
name: "random",
description: "hello",
status: "true",
asset: [],
version: "0.043",
}
您可以使用扩展操作符来复制data
和item
。然后可以在redux部分的代码
data = { ...data, item: [...data.item, ...item] };