我想把一个嵌套对象传递到redux reducer中,我知道我必须使用。。。操作员进行深度复制。但我找不到如何传递/复制'comments'数组和嵌套在'comments'数组的每个元素中的'_user'对象集。
{
"mess": "",
"article": {
"_id": "5faba634513b091effd8c37f",
"article": "intoheadLifestyle",
"likeArt": 0,
"dislikeArt": 0,
"comments": [
{
"_id": "5faba635513b091effd8c381",
"commentId": {
"_id": "5faba634513b091effd8c380",
"comment": "finish for today, all is working as expected, even better .....",
"like": 0,
"dislike": 0,
"_user": {
"_id": "5fa93d08533de7437c77a5a0",
"username": "jerome",
"password": "$2b$10$is66cqM5K5ZE/z7T34a54e0TNXSrdVZIx7jF5sqkZQ1gAwOplt4Si",
"__v": 0
},
"createdAt": "2020-11-11T08:52:04.960Z",
"__v": 0
}
},
{
"_id": "5faba64b513b091effd8c383",
"commentId": {
"_id": "5faba64a513b091effd8c382",
"comment": "another coent ca c bien coool",
"like": 0,
"dislike": 0,
"_user": {
"_id": "5fa93d08533de7437c77a5a0",
"username": "jerome",
"password": "$2b$10$is66cqM5K5ZE/z7T34a54e0TNXSrdVZIx7jF5sqkZQ1gAwOplt4Si",
"__v": 0
},
"createdAt": "2020-11-11T08:52:26.995Z",
"__v": 0
}
}
],
"__v": 2
}
}
这个物体是由";res.payload.data";,所以我试着做
let datas = {...res.payload.data,
article: {...res.payload.data.article,
// then i don t know for the 'comments' array ..???
// and i am lost for the '_user' object into each element of the array...
如果有人有主意,谢谢你。
我想你的意思是扩展数组[...value]
let datas = {
...res.payload.data,
article: {
...res.payload.data.article,
comments: [...res.payload.data.article.comments],
},
}
好的,我理解如何传递评论[],谢谢。
但是,如何将"_user"对象传递到"comments"数组的每个元素中,它也需要传播(我不知道我们是否这样说。(。。。