reactjs - 使用 js operator ... 将数据传递到 redux reducer
问题描述
我想将嵌套对象传递给 redux reducer,我知道我必须使用 ... 运算符来进行深层复制。但我不知道如何传递/复制“评论”数组和嵌套在“评论”数组的每个元素中的“_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...
如果有人有想法,谢谢。
解决方案
好的,我了解如何传递评论[],谢谢。
但是如何将'_user'对象传递到'comments'数组的每个元素中,它也需要传播(我不知道我们是否这样说。)以及......
推荐阅读
- python - 如何绘制颜色 QtGui.QPainterPath.addRect()?
- ajax - Prestashop:将数据从 js 文件传递到控制器到自定义页面
- javascript - 如何添加新行但不在第一个 x 轴中
- python-3.x - 返回一本字典,用 Scrapy 抓取多个页面
- javascript - 多选插件不显示任何选项
- python - 使用 Builder.load_string 在 Kivy 应用程序上显示变量
- python - 如何使用 Bokeh 生成气泡图
- python - 在 python 中窗口化写入,例如写入 NetCDF
- ruby-on-rails - SidekiqUniqueJobs::UnknownLock: 没有实现`lock::all`
- android - Nativescript - 原生安卓蓝牙低功耗