【发布时间】:2019-08-25 11:24:02
【问题描述】:
我正在开发一个反应博客应用程序,其中列出了文章和对文章的评论。我正在使用 JSON 文件将数据存储在本地。 我添加了添加新评论的按钮。我无法将新评论添加到 JSON 数据。
我已将数据导入到我的组件文件中。我被困在如何更新 JSON 上。
[{
"id": "5d403e5fbe39eb87471b8cd9",
"title": "laboris duis veniam",
"content": "Sint quis nisi tempor officia. occaecat pariatur sunt.\r\n",
"author":
{
"_id": "5d403e5f552ff12f1d0773d0",
"name": "Amanda Mckinney"
},
"comments": [
{
"id": "5d403e5f416a8a6b0447a069",
"content": "Do minim Culpa nostrud laborum consectet\r\n",
"commenter":
{
"_id": "5d403e5f58174caa22041e78",
"name": "Angelina Wong"
}
},
{
"id": "5d403e5f17475a36a4745241",
"content": "Velit reprehenderit et consectetur id in .\r\n",
"commenter":
{
"_id": "5d403e5f3511fa317d0bf561",
"name": "Gail Moss"
}
},
{
"id": "5d403e5f8419bad3767550b1",
"content": "Labore veniam dolor deserunt qui minim.\r\n",
"commenter":
{
"_id": "5d403e5f28bd1b5fc4d1be1b",
"name": "Staci Pierce"
}
},
{
"id": "5d403e5f43a52dd53b63f6c6",
"content": "Pariatur quis proident dolor veniam laborum.\r\n",
"commenter":
{
"_id": "5d403e5f33be38b996c4a8f1",
"name": "Mai Delaney"
}
},
{
"id": "5d403e5f9c53f6000ca12607",
"content": "Labore reprehenderit pariatur culpa non\r\n",
"commenter":
{
"_id": "5d403e5f1f77294e7fc77552",
"name": "Geraldine Gilliam"
}
}]
}]
在评论会话中,我想添加带有详细信息的新评论对象,例如
{
"id": "5d403e5f9c53f6000ca12607",
"content": "Labore reprehenderit pariatur culpa non\r\n",
"commenter": {
"_id": "5d403e5f1f77294e7fc77552",
"name": "Geraldine Gilliam"
}
}
【问题讨论】:
标签: json reactjs react-redux