当我在 react-native 中点击 TouchableOpacity 时,如何在 state.when 中获取文本的值? [英] How to get value of text in state.when i clicked on TouchableOpacity in react-native?
本文介绍了当我在 react-native 中点击 TouchableOpacity 时,如何在 state.when 中获取文本的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 TouchableOpacity 的文本中有性别价值.所以我想在我点击 TouchableOpacity 时获得所选性别的值.
I have gender value in text of TouchableOpacity . so I want to get value of selected gender in state when i clicked on TouchableOpacity.
所以请帮助我如何实现这个功能.先谢谢你.
So please help me how i can achieve this functionality.Thank you in advanced.
这是我屏幕的一部分,你可以在下面看到.
This is some part of my screen you can see below.
推荐答案
像这样创建函数
setGender=(props)={
this.setState({gender:props})
}
像这样从按钮 onPress 调用这个函数
call this function from button onPress like this
onPress={()=>this.setGender("Male")}
onPress={()=>this.setGender("Female")
并在文本中显示状态值
这篇关于当我在 react-native 中点击 TouchableOpacity 时,如何在 state.when 中获取文本的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文