作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在 onPress 函数中访问 React Native 元素属性,我尝试使用 event.target 和 ReactNativeComponentTree 但它不起作用,我想在 OnPress 函数中访问 audioPath 属性
<Ionicons
name="ios-play"
size={35}
color={this.state.playAudio ? "red" : "blue"}
style={{
left: 90,
position: "relative",
shadowColor: "#000",
shadowOffset: { width: 0, height: 0 },
shadowOpacity: 0.5,
backgroundColor: "transparent"
}}
audioPath= {audioPath}
onPress={this.audioPathFunction.bind(this)}
/>
最佳答案
<Ionicons
name="ios-play"
size={35}
color={this.state.playAudio ? "red" : "blue"}
style={{
left: 90,
position: "relative",
shadowColor: "#000",
shadowOffset: { width: 0, height: 0 },
shadowOpacity: 0.5,
backgroundColor: "transparent"
}}
audioPath= {audioPath}
onPress={()=> this.audioPathFunction(audioPath)}
/>
视情况而定。你可以在内部访问它,如果它的状态变量/类变量你可以在任何地方访问它,甚至在 onPress 函数内部。如果它仅在 render() 中可用,请使用上面的指针函数(这不是一个好方法)
关于javascript - 如何在 onPress 函数中访问 React Native 标签或元素的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57438975/
我是一名优秀的程序员,十分优秀!