【发布时间】:2020-12-09 11:39:48
【问题描述】:
几天来一直在尝试对此进行排序,但无济于事。
在 ReactJS 中有一个对象数组,我试图在其中编辑数组中某个项目的元素:
对象结构如下:
actor: null
aggregate: "Comment"
aggregateId: "5fcf206131414a05bcee9f88"
createdAt: "2020-12-08T06:42:41.983Z"
data: {…}
comment: {…}
author: Object { id: "5ea683231fac57758ae7e4e2", nodeId: "MDQ6VXNlcjI1MTc0ODQ=", username: "monstertrux", … }
body: "ths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdf\n\nths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdf\n\nths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdfths is an edit testsfsdfsdf"
createdAt: "2020-12-08T06:42:41.983Z"
id: "5fcf206131414a05bcee9f88"
topicId: "5f3e3eb92db37843068c045a"
updatedAt: "2020-12-09T10:32:05.889Z"
<prototype>: Object { … }
<prototype>: Object { … }
event: null
id: "5fcf206131414a05bcee9f88"
message: null```
have been trying to navigate the array and then edit the comment field with the following:
让 itemToEdit = tempTimeline[foundIndex] console.log(itemToEdit)
itemToEdit = {...itemToEdit, data.comment.body: comment }
which pulls the item to be edited from the array and then tries to edit the data.comment.body element in the hierarchy.
But all I get for my efforts is the following errors:
No value exists in scope for the shorthand property 'data'. Either declare one or provide an initializer.
',' expected.
Type '{ data: any; "": any; comment: string; id?: string | undefined; aggregateId?: string | undefined; aggregate?: string | undefined; event?: string | null | undefined; message?: string | null | undefined; actor?: Member | ... 1 more ... | undefined; createdAt?: string | undefined; }' is not assignable to type 'IssueTimeline'.
Object literal may only specify known properties, and '(Missing)' does not exist in type 'IssueTimeline'.
',' expected.
Anyone have any idea what I am doing wrong here?
【问题讨论】:
标签: reactjs typescript object