如何使单选按钮遍历数组

时间:2018-09-03 05:54:14

标签: react-native

我正在使用react-native-flexi-radio-button(https://github.com/thegamenicorus/react-native-flexi-radio-button),但是我想使用json值循环播放单选按钮,并且它不起作用。看看下面的代码。预先感谢

这有效

<RadioGroup
  onSelect={(index, value) => this.onSelect(index, value)}>

  <RadioButton value={"item1"}>
    <Text>This is item #1</Text>
  </RadioButton>

</RadioGroup>

但是以下给出的内容无法读取null的属性“ props”

<RadioGroup
  onSelect={(index, value) => this.onSelect(index, value)}
>
  {this.state.cuisinesByFoodList.map(item1 => {
    console.log("result", item1);
    <RadioButton value={"abc"}>
      <Text>{"abc"}</Text>
    </RadioButton>;
  })}
</RadioGroup>

P.S there's value in item1 in the console when debugged.

1 个答案:

答案 0 :(得分:0)

您忘记return了。

<RadioGroup
  onSelect={(index, value) => this.onSelect(index, value)}
>
  {this.state.cuisinesByFoodList.map(item1 => {
    console.log("result", item1);
    return(<RadioButton value={"abc"}>
      <Text>{"abc"}</Text>
    </RadioButton>);
  })}
</RadioGroup>