Javascript 如果在react native中未选中所有复选框,如何禁用按钮
有3个复选框,我必须使一个复选框为必填项。若所有复选框都未选中,那个么按钮应该被禁用。请帮帮我。我能做什么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
<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我不是问题的所有者。谢谢大家,大家都知道我做了很多事情,或者这就是原因。。感谢我所做的一切,这就是为什么。。谢谢