无法在反应状态下处理嵌套数组,这里我正在尝试我需要在 this.state.form.contentFormArr 中推送值
let langulageform, contentObj,contentFormArr;
contentObj={heading:'',subheading:''};
contentFormArr=[this.contentObj]
langulageform =[
{key:"Ar",lang:"Arabic",contentFormArr:this.contentFormArr},
{key:"En",lang:"English",contentFormArr:this.contentFormArr},
{key:"Ru",lang:"Russian",contentFormArr:this.contentFormArr},
{key:"Sp",lang:"Spanish",contentFormArr:this.contentFormArr},
{key:"Ve",lang:"Vetnamese",contentFormArr:this.contentFormArr}
];
constructor(){
super()
this.addContentArea = this.addContentArea.bind(this)
this.state={
form:this.langulageform
}
}
addContentArea(index){
this.setState((state)=>{
const contentformArr = [...state.form[index].contentFormArr,this.contentObj]
return{
...state.form.contentFormArr,
contentformArr
}
})
}
我通过迭代 this.state.form 数组制作了多个表单,现在我需要当用户单击任何表单框按钮以添加更多字段时,它将推送特定索引数组中的值,然后它将迭代更多字段。