constructor(){super();this.state={alll:[],values:''}}add(e){letarr1=this.state.alll;arr1.push({msg:this.state.values,check1:false});this.setState({alll:arr1})//console.log(this.state.alll);}delate(e){letindex1=e.target.parentNode.id;letarr1=[];for(vari=0;iarr1.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
青春有我
守着一只汪
相关分类