OGeek|极客世界-中国程序员成长平台

标题: javascript - react native - 如何在构造函数中使用状态 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:26
标题: javascript - react native - 如何在构造函数中使用状态

我想在另一个状态的定义中使用一个状态,但我没有得到任何值(value)。
有人有什么想法吗??

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()}
            />
    )

    };


}



Best Answer-推荐答案


你可以在你的组件中使用它

 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>}
}

关于javascript - react native - 如何在构造函数中使用状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45456011/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4