菜鸟教程小白 发表于 2022-12-11 18:26:10

javascript - react native - 如何在构造函数中使用状态


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

<pre><code>constructor(props) {

    super(props);

    this.state = {

      check : false,
      datatotal : this.props.services.map((d) =&gt;
            &lt;CheckBox
                center
                title={d}
                checkedIcon=&#39;dot-circle-o&#39;
                uncheckedIcon=&#39;circle-o&#39;
                checked= {true}
                onPress={() =&gt; this.checkBoxClick()}
            /&gt;
    )

    };


}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>你可以在你的组件中使用它</p>

<pre><code> constructor(props){
super(props);
this.state = {
   check: false
   }
}

render() {
&lt;View&gt;
{this.props.services &amp;&amp; this.props.services.map(
&lt;CheckBox
            center
            title={d}
            checkedIcon=&#39;dot-circle-o&#39;
            uncheckedIcon=&#39;circle-o&#39;
            checked= {true}
            onPress={() =&gt; this.checkBoxClick()}
      /&gt;
)&lt;/View&gt;}
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于javascript - react native - 如何在构造函数中使用状态,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/45456011/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/45456011/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: javascript - react native - 如何在构造函数中使用状态