【问题标题】:How to get labels for radio button from array in React Native?如何从 React Native 中的数组中获取单选按钮的标签?
【发布时间】:2018-07-03 16:03:56
【问题描述】:

我有单选按钮from internet 的示例。但我只在下面写我用过的。但现在我需要从字符串数组中获取标签

我不太清楚我将如何实现它,希望有人可以帮助我。

图书馆

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

标签

var hobbies = [
  {label: "Teasing", value: 0},
  {label: "Catching plate", value: 1},
  {label: "Soaking in the mud", value: 2},
];

查看

<View style={styles.container}>
    <RadioForm
      radio_props={hobbies}
      initial={0}
      onPress={(value) => alert(value)}}
    />
  </View>

应该去哪里

{this.state.involvedFriends.map((name, key) => (
   <View>
      <RadioForm />
   </View>
 ))}

【问题讨论】:

    标签: reactjs react-native radio-button


    【解决方案1】:

    你可以像这样在构造函数中创建爱好数组:

    //define an empty array
    private hobbies = [] 
    
    makeOtions = () => {    // call it after involvedFriends is initialized.
        this.state.involvedFriends.map((name, key) => (
            hobbies.push({label: name, value: key}}
        ))
    }
    

    现在,您可以通过radio_props={this.hobbies} 将爱好传递给电台

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 1970-01-01
      • 2019-02-10
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多