gpt4 book ai didi

javascript - 如何在 onPress 函数中访问 React Native 标签或元素的属性?

转载 作者:行者123 更新时间:2023-11-28 03:39:14 24 4
gpt4 key购买 nike

我想在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com