首页 > 解决方案 > react-native 中的条件复选框

问题描述

我想得到一点帮助。我试图创造一个条件。如果产品有库存;必须选中复选框。如果不是,它必须是空的。我一点一点地摸索,我迷失在我的代码中。你能给我一点帮助吗?

感谢您的帮助和时间。

这是代码的一部分(我知道条件根本不正确,这只是一些事情的开始):

export default class Products extends Component {
  constructor(props) {
    super(props);
    this.state = {
      checked: true,
      stock : true, 
    }
  };

...

     <View style={{ flexDirection: 'row' }}>
       <CheckBox
          value={this.state.stock ? !this.state.checked}
          //onValueChange={() => this.setState({ checked: !this.state.checked })}
       />
       <Text style={{marginTop: 5}}>Stock</Text>
     </View>      

标签: react-nativecheckboxconditional-statements

解决方案


试试这个

<View pointerEvents="none">
  <CheckBox
    value={this.state.stock}
    //onValueChange={() => this.setState({ checked: !this.state.checked })}
  />
</View>

推荐阅读