constructor(){ super(); this.state={ alll:[], values:'' } } add(e){ let arr1 = this.state.alll; arr1.push({msg:this.state.values,check1:false}); this.setState({ alll:arr1 }) // console.log(this.state.alll); }delate(e){ let index1 = e.target.parentNode.id; let arr1 = []; for(var i =0;i<this.state.alll.length;i++){ arr1.push(JSON.parse(JSON.stringify(this.state.alll[i]))); } console.log(arr1); arr1.splice(index1,1); console.log(arr1); this.setState( function(){ return {alll: arr1}; } ) console.log(this.state.alll);// }调用delate方法时,state中的数组alll不会改变为删除一个元素后的arr1。直接使用setState({alll:arr1})也是同样的效果,无法改变alll
添加回答
举报
0/150
提交
取消