[英]How to render checked/selected radio button using radioForm in react native
[英]Index wise Setstate onpress funtion for Radioform in react native
您好,我是React Native的新用戶。 我需要一個在平面列表中具有無線電格式的解決方案。 因此,將有與平面列表行渲染相同數量的無線電形式。 我想設置狀態以響應本機onpress功能。 因為我可以獲取radioform的狀態值,但是我想明智地使用索引。 因此,如何為Radioform設置狀態索引明智。 這是我在列表中的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}
/>
也許您可以在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>
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.