Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果在react native中未选中所有复选框,如何禁用按钮_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript 如果在react native中未选中所有复选框,如何禁用按钮

Javascript 如果在react native中未选中所有复选框,如何禁用按钮,javascript,reactjs,react-native,Javascript,Reactjs,React Native,有3个复选框,我必须使一个复选框为必填项。若所有复选框都未选中,那个么按钮应该被禁用。请帮帮我。我能做什么 <View style={{ flexDirection: 'row', paddingLeft: 15 }}> <View style={{ flex: 1 }}> <CheckBox color="#00678f" checked={this.state.notification.isContactByPost} on

有3个复选框,我必须使一个复选框为必填项。若所有复选框都未选中,那个么按钮应该被禁用。请帮帮我。我能做什么

<View style={{ flexDirection: 'row', paddingLeft: 15 }}>
  <View style={{ flex: 1 }}>
    <CheckBox color="#00678f" 
      checked={this.state.notification.isContactByPost}
      onPress={() => this.handleChange('isContactByPost')} 
    />
 </View>
 <View style={{ flex: 1 }}>
   <Text style={{ fontSize: 14 }}>Post</Text>
 </View>
 <View style={{ flex: 1 }}>
   <CheckBox color="#00678f"
     checked={this.state.notification.isContactByEmail}
     onPress={() => this.handleChange('isContactByEmail')} 
   />
 </View>
 <View style={{ flex: 1 }}>
   <Text style={{ fontSize: 14 }}>Email</Text>
 </View>
 <View style={{ flex: 1 }}>
   <CheckBox color="#00678f"
     checked={this.state.notification.isContactBySms}
     onPress={() => this.handleChange('isContactBySms')}
   />
 </View>
 <View style={{ flex: 1 }}>
   <Text style={{ fontSize: 14 }}>SMS</Text>
 </View>
</View>  
<View style={{ marginTop: 50 }}>
 <PrimaryBtn 
   label={'submit'}
   disabled={false}
   onPress={() => this.OnButtonClick(this.state.notification)} 
 />
 </View>
 </View>

this.handleChange('isContactByPost')}
/>
邮递
this.handleChange('isContactByEmail')}
/>
电子邮件
this.handleChange('isContactByMs')}
/>
短讯服务
this.onbutton单击(this.state.notification)}
/>

谢谢

这就是你能做到的

<PrimaryBtn label={'submit'} disabled={!this.state.notification.isContactByPost && 
    !this.state.notification.isContactByEmail && 
    !this.state.notification.isContactBySms}  onPress={() => 
    this.OnButtonClick(this.state.notification)} />

this.onbutton单击(this.state.notification)}/>

希望这对你有所帮助这是你可以做到的

<PrimaryBtn label={'submit'} disabled={!this.state.notification.isContactByPost && 
    !this.state.notification.isContactByEmail && 
    !this.state.notification.isContactBySms}  onPress={() => 
    this.OnButtonClick(this.state.notification)} />

this.onbutton单击(this.state.notification)}/>
希望这有帮助
render(){
const{isContactByPost、isContactByEmail、isContactByMs}=this.state.notification;
返回(
this.onbutton单击(this.state.notification)}
/>
);
}
render(){
const{isContactByPost、isContactByEmail、isContactByMs}=this.state.notification;
返回(
this.onbutton单击(this.state.notification)}
/>
);
}
试试这个(为了更简单,我删除了多余的部分)=>

const{isContactByPost、isContactByEmail、isContactByMs}=this.state.notification
常量isButtonDisabled=!(isContactByPost | | | isContactByEmail | | IsContactByMS)
//不要忘记你的其他道具:)
试试这个(为了更简单,我删除了多余的部分)=>

const{isContactByPost、isContactByEmail、isContactByMs}=this.state.notification
常量isButtonDisabled=!(isContactByPost | | | isContactByEmail | | IsContactByMS)
//不要忘记你的其他道具:)

进行一项强制性更改
disabled={false}
disabled={!this.state.notification.isContactByPost}
例如,进行isContactByPost强制执行感谢您的帮助,但是有3个框如果所有选项都未选中,则应在2个选项上禁用其他选项如果@Deckerz解决方案不起作用,则应启用,你能告诉我们你的
handleChange
方法吗?@IanStebanVasco我不是问题的所有者。要将
disabled={false}
强制更改为
disabled={!this.state.notification.isContactByPost}
,例如,要使isContactByPost强制执行感谢你的帮助,但是有3个框,如果全部未选中,那么它应该在2个未选中的框上禁用else。它应该启用如果@Deckerz解决方案不起作用,你能给我们看看你的
handleChange
方法吗?@IanStebanVasco我不是问题的所有者。谢谢大家,大家都知道我做了很多事情,或者这就是原因。。感谢我所做的一切,这就是为什么。。谢谢