[英]push new array of object into existing array of object using spread of ES6
Is this syntax even correct? 这种语法甚至正确吗? results is my array of object, it's nested.
结果是我的对象数组,它是嵌套的。
notifications: {
...state.notifications,
results: [
...state.notifications.results,
{ ...state.notifications.results }
]
}
This should be work. 这应该是可行的。
notifications: {
...state.notifications,
results: [
...state.notifications.results
]
}
It seems to me that you're trying to run this.setState
, and update your array whilst doing so. 在我看来,您正在尝试运行
this.setState
并同时更新数组。
The full command would be something like this: 完整的命令将如下所示:
this.setState({
notifications: {
...this.state.notifications,
results: [
...this.state.results,
// whatever you're trying to add goes here
]
}
});
I'm just guessing based upon the tags on your question. 我只是根据您问题的标签进行猜测。 Feel free to comment and explain your situation further so I can tailor my answer to better suit your question.
请随时发表评论并进一步说明您的情况,以便我调整答案以更好地适合您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.