我用 nextjs 构建电子商务网站,
我有包含产品数据的产品表格
这是虚拟数据:
{
id: "1",
name: "قميص لاكسوت",
description: "فول كفر خامه قطن ليكرا",
rating: 4,
total_sell: 35,
images: [
{
url: "/public/56774684-c63b-4835-b419-a330a61eeccc.jpeg",
},
{
url: "/public/56774684-c63b-4835-b419-a330a61eeccc.jpeg",
},
{
url: "/public/56774684-c63b-4835-b419-a330a61eeccc.jpeg",
},
],
category: {
name: "قمصان",
gender: "حريمي",
},
sizes: [
{
id: "1",
size: "l",
colors: [
{ id: "1", color: "red", stock: 10 },
{ id: "2", color: "black", stock: 5 },
],
},
{
id: "2",
size: "xl",
colors: [
{ id: "1", color: "blue", stock: 15 },
{ id: "2", color: "white", stock: 50 },
],
},
],
createdAt: new Date("2023-08-12T03:49:42.714+00:00"),
},
我尝试添加尺寸字段,并在内部尝试添加颜色字段
我无法到达这个颜色数组
这是我添加尺寸字段的代码
const handleAddSize = () => {
const productCopy = JSON.parse(JSON.stringify(product));
productCopy.sizes = [
...productCopy.sizes,
{ size: "", colors: [{ color: "", stock: 0 }] },
];
setProduct(productCopy);
};
当我尝试以同样的方式达到色域时,它不起作用
const handleAddColors = () => {
setProduct({
...product,
sizes: [
...product.sizes,
{colors: [...product.sizes.colors, { color: "", stock: 0 }] }
],
});
};
我尝试了几种方法但没有成功