gpt4 book ai didi

javascript - 数组对象更新 React SetState

转载 作者:行者123 更新时间:2023-11-30 14:49:56 24 4
gpt4 key购买 nike

<分区>

我很困在这里我有这样的状态

state={
panelData:[
{ title:"title"
content:["one",2]
}
]
}

现在在我的 setState 中我想添加新的标题和内容,还有我以前添加的数据,所以两个对象对吗?像这样

panelData: [     {title:"title",content:["one",2]} ,
{title:"title 2"content:[3,4]} ]

我试过了

    handlingAddRecipe(){ //this is my update paneldata function
let contentValue = this.state.recipeContent.join("").split(","); //contentValue = ["content1","content2"]

this.setState({
panelData:[{
title:this.state.recipeTitle, //title:"title1"
content:contentValue //content:contentValue
}]
})
console.log(this.state.panelData)
}

我得到的输出没有以前的数据,只有传递给面板数据的数据

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com