我每天都在创建数据,并且正在处理以下响应数据......
{
tipster: {
name: "Gallita FC",
description: "TEST",
picks: [{
date: "Friday, February 18th 2022",
data: [{
title: "yesterday",
description: "TEST",
date: "Friday, February 18th 2022",
category: "NHL",
pickImageUrl: "https://res.cloudinary.com/creaciones-inteligentes-roy/image/upload/v1644455039/Captura_de_Pantalla_2022-02-09_a_la_s_18.59.43_voy1pj.png",
}],
}, {
date: "Saturday, February 19th 2022",
data: [{
title: "today",
description: "TEST",
date: "Saturday, February 19th 2022",
category: "NHL",
pickImageUrl: "https://res.cloudinary.com/creaciones-inteligentes-roy/image/upload/v1644455039/Captura_de_Pantalla_2022-02-09_a_la_s_18.59.43_voy1pj.png",
}],
}],
imageUrl: "https://res.cloudinary.com/sports-master/image/upload/v1644649610/27ADF778-454B-4DB7-88B7-DC98202E2736_utb7xw.png",
bannerUrl: "https://scontent.fmex34-1.fna.fbcdn.net/v/t1.6435-9/167022015_1317341031983063_7337313589197318410_n.jpg?_nc_cat=111&ccb=1-5&_nc_sid=a26aad&_nc_ohc=5ctqP2nFf7IAX94PNSO&_nc_ht=scontent.fmex34-1.fna&oh=00_AT_TzRHhhV73ji7wzW2X1u27TOU8TNlObwtp0ILc0DzC1Q&oe=62207F2C",
id: "62075e5a13a43ace611fe5bd",
},
}
在tipster.picks
数组中,我需要data
在最后一个匹配项上附加一个附加data
项。匹配可能是 where data.title
equals "today"
。
到目前为止我想出的代码并没有导致正确的结果......
const newPick = {
title,
description,
date,
category,
pickImageUrl,
};
const tipsterUpdate = {
...req.body,
picks: [...tipster.picks, tipster.picks.slice(-(1)[0], newPick)],
};
我正在使用扩展运算符,因为我需要维护旧数据并且只在数据数组上添加一个新对象。
我真的很感谢这里的一点帮助。谢谢你。