Javascript 如何禁用Moschan';s react原生简单单选按钮

Javascript 如何禁用Moschan';s react原生简单单选按钮,javascript,react-native,Javascript,React Native,我正在使用Moschan的,很难禁用一些单选按钮。我已尝试使用值true或1传递disabled项参数,但运气不佳,它仍然是可选择的 来源: radio_props = [ { value: 1, label: 'one', disabled: true }, { value: 2, label: 'two' }, { value: 3, label: 'three', disabled: true }, ]; import RadioForm from 'react-

我正在使用Moschan的,很难禁用一些单选按钮。我已尝试使用值
true
1
传递
disabled
项参数,但运气不佳,它仍然是可选择的

来源

radio_props = [
    { value: 1, label: 'one', disabled: true },
    { value: 2, label: 'two' },
    { value: 3, label: 'three', disabled: true },
];
import RadioForm from 'react-native-simple-radio-button';

...
<RadioForm
    radio_props={radio_props}
    initial={-1}
    buttonColor={'#169976'}
    selectedButtonColor={'#169976'}
    buttonSize={12}
    buttonOuterSize={25}
    onPress={(value) => { this.setState({ value:value }); }}
  />
...
组件

radio_props = [
    { value: 1, label: 'one', disabled: true },
    { value: 2, label: 'two' },
    { value: 3, label: 'three', disabled: true },
];
import RadioForm from 'react-native-simple-radio-button';

...
<RadioForm
    radio_props={radio_props}
    initial={-1}
    buttonColor={'#169976'}
    selectedButtonColor={'#169976'}
    buttonSize={12}
    buttonOuterSize={25}
    onPress={(value) => { this.setState({ value:value }); }}
  />
...
从“react native simple单选按钮”导入无线表单;
...
{this.setState({value:value});}
/>
...

你知道怎么解决这个问题吗?请告知。

您可以将禁用的道具传递给RadioButtonLabel和RadioButtonInput。如果它被禁用,它将不会调用onPress函数。例如,您可以执行以下操作

<RadioButton>
  <RadioButtonInput
      {...otherRadioButtonInputProps}
      disabled={shouldDisable}
      buttonInnerColor={shouldDisable ? '#EEE' : '#000'}
      buttonOuterColor={shouldDisable ? '#EEE' : '#000'}
  />
  <RadioButtonLabel
      {...otherRadioButtonLabelProps}
      disabled={shouldDisable}
  />
</RadioButton>

您可以将禁用的道具传递给RadioButtonLabel和RadioButtonInput。如果它被禁用,它将不会调用onPress函数。例如,您可以执行以下操作

<RadioButton>
  <RadioButtonInput
      {...otherRadioButtonInputProps}
      disabled={shouldDisable}
      buttonInnerColor={shouldDisable ? '#EEE' : '#000'}
      buttonOuterColor={shouldDisable ? '#EEE' : '#000'}
  />
  <RadioButtonLabel
      {...otherRadioButtonLabelProps}
      disabled={shouldDisable}
  />
</RadioButton>

我通过以下步骤解决了这个问题:

  • 打开node_modules/react native simple单选按钮/lib/SimpleRadioButton.js
  • 查找第72行附近的
    disabled={this.props.disabled}
    ,修改为:
    disabled={this.props.disabled | | obj.disabled?obj.disabled:false}
  • 保存并重试

希望这能有所帮助。

我通过以下步骤解决了这个问题:

  • 打开node_modules/react native simple单选按钮/lib/SimpleRadioButton.js
  • 查找第72行附近的
    disabled={this.props.disabled}
    ,修改为:
    disabled={this.props.disabled | | obj.disabled?obj.disabled:false}
  • 保存并重试

希望这有帮助。

此方法效果很好,谢谢。但是现在,选中的单选按钮缺少内点,如果我们不提取该单选按钮,则不会发生这种情况。此方法很有效,谢谢。但是现在,选中的单选按钮缺少内点,如果我们不提取无线形式,就不会发生这种情况。