本地反应-如何在构造函数中使用状态

他们

我想在定义其他状态时使用一个状态,但是我什么也没得到。
有人有什么想法吗?

constructor(props) {

    super(props);

    this.state = {

        check : false,
        datatotal : this.props.services.map((d) =>
            <CheckBox
                center
                title={d}
                checkedIcon='dot-circle-o'
                uncheckedIcon='circle-o'
                checked= {true}
                onPress={() => this.checkBoxClick()}
            />
    )

    };


}
沙松子·阿迪

您可以在组件内部使用它

 constructor(props){
 super(props);
  this.state = {
     check: false
   } 
} 

render() {
 <View>
 {this.props.services && this.props.services.map(
  <CheckBox
            center
            title={d}
            checkedIcon='dot-circle-o'
            uncheckedIcon='circle-o'
            checked= {true}
            onPress={() => this.checkBoxClick()}
        />
  )</View>}
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章