这样写每回点击删除都会产生一个li
让他不产生又会报错,如果给他父级加getInitialState的话有只有一次,请问该如何解决
var ProductionSectionBox=React.createClass({
getInitialState : function(){
return {
flay : true
}
},
ChangeDevice : function(){
this.setState({flay: !this.state.flay});
},
render : function(){
var filterArr=this.props.data;
var key=this.props.key;
if(this.state.flay){
return (
{filterArr}
)
}else{
return (
)
}
}
})
//删除的代码
var ProductionSectiontool=React.createClass({
handleremove : function(){
this.props.flay();
},
render :function(){
return(
-
-
-
)
}
})
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
原先我也碰到过类似的错误,就是返回正确DOM和返回空。
你可以
<ProductionSectiontool flay={this.ChangeDevice}/>
应写为
<ProductionSectiontool flay={this.ChangeDevice.bind(this)}/>
因为这方法里用了this,如不绑定this.setState将报错