【问题标题】:Index wise Setstate onpress funtion for Radioform in react nativeRadioform 在本机反应中的索引明智的 Setstate onpress 功能
【发布时间】:2018-08-30 07:01:41
【问题描述】:

你好,我是 React Native 的新手。我需要一个解决方案,我在 flatlist 中有 radioform。所以会有与平面列表行渲染相同数量的radioform。我想为反应原生 onpress 功能设置状态。因为我能够获得 radioform state 的值,但我想获得 index wise 。那么如何为 Radioform 明智地设置 State 索引。这是我在平面列表中的 Radioform 代码。

 <RadioForm
            animation={true}
            buttonColor={"#C2E3A9"}
            index={index}
            formHorizontal={true}
            labelHorizontal={true}
            buttonStyle={{ marginRight: 20 }}
            radioStyle={{ paddingRight: 20 }}
            //  labelHorizontal={false}
            style={styles.radiostyle}
            radio_props={radio_props}
            initial={this.state.typeofattendance[1]}
            isSelected = {true}

            **onPress={value => {this.setState({ typeofattendance: value});

              }**
            }
            ItemSeparatorComponent={this.renderSeparator}
          />

【问题讨论】:

    标签: android react-native radio-button react-native-flatlist


    【解决方案1】:

    也许你可以在 FlatList 的 renderItem 中添加索引

    renderItem = ({item, index}) => {       
        return(   
            <View>
               <RadioForm
                animation={true}
                buttonColor={"#C2E3A9"}
                index={index}
                formHorizontal={true}
                labelHorizontal={true}
                buttonStyle={{ marginRight: 20 }}
                radioStyle={{ paddingRight: 20 }}
                //  labelHorizontal={false}
                style={styles.radiostyle}
                radio_props={radio_props}
                initial={this.state.typeofattendance[1]}
                isSelected = {true}
    
                **onPress={value => {this.setState({ typeofattendance: value, index: index
    });
    
                  }**
                }
                ItemSeparatorComponent={this.renderSeparator}
              />
            </View>
          );
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-02
      • 1970-01-01
      • 2017-11-16
      • 2018-06-22
      • 2017-11-09
      • 1970-01-01
      • 2021-05-30
      • 2021-05-17
      相关资源
      最近更新 更多