【问题标题】:Need to populate value based on radio button input in reactjs需要根据 reactjs 中的单选按钮输入填充值
【发布时间】:2021-02-02 05:26:57
【问题描述】:

我想根据单选按钮输入填充文本字段的值,例如,如果单选按钮输出为“是”,那么它将文本字段值设置为“这是来自是”,如果单选按钮输出值为“否”,那么它将将文本字段值设置为“This is from no”

【问题讨论】:

标签: javascript reactjs react-native rxjs


【解决方案1】:

这可能有助于react-native-simple-radio-button

import RadioForm, {RadioButton, RadioButtonInput, RadioButtonLabel} from 'react-native-simple-radio-button';
import { Text } from "react-native";


var radio_props = [
  {label: ‘Yes’, value: "This is from yes" },
  {label: ‘No’, value: "This is from no" }
];

export default class App {

  state = { textValue: radio_props[0].value} 
  
  render() {
    return (
      <View>
        <RadioForm
          radio_props={radio_props}
          initial={0}
          onPress={(value) => {this.setState({textValue:value})}}
        />
        <Text>{this.state.textValue}</Text>
      </View>
    );
  }
}

【讨论】:

  • 如果有帮助,请更正答案投票:-)
猜你喜欢
  • 2011-12-25
  • 2012-09-19
  • 2020-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-09
  • 2011-11-24
相关资源
最近更新 更多