代码之家  ›  专栏  ›  技术社区  ›  beck

如何在数组中循环单选按钮

  •  0
  • beck  · 技术社区  · 6 年前

    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>
    

    但是下面的give无法读取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 回复  |  直到 6 年前
        1
  •  0
  •   Ahsan Ali    6 年前

    你忘了 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>