0
我试图按FlatList中的一行,并使应用程序导航到另一个页面,我试图做到这一点,而无需为每个渲染创建新的方法。我如何知道我按下了哪个TouchableNativeFeedback?
使用做出反应,我只想从event.target
获得的价值,但我无法这样做,在反应本土
这是我到目前为止有:
constructor(props){
super(props)
this._renderListItem = ({ item }) => this.renderListItem(item)
this._onPressListItem =() => this.onPressListItem()
}
onPressListItem() {
// Right here I need to know which row I pressed
this.props.navigation.navigate('ChatScreen', {})
}
renderListItem(item) {
return (
<TouchableNativeFeedback onPress={this._onPressListItem}>
<View style={{ height: 50, backgroundColor: 'red' }}>
<Text>{item.name}</Text>
</View>
</TouchableNativeFeedback>
)
}
该行中按下的票面项的值谢谢你的反应,但我用此溶液看到的问题是,每时间一个新的ListItem被创建'onPress'创建一个新的函数只是为了这个绑定,即时尝试避免这种情况。 – JCRamires
你可以使用地图,因为你只需要传递items数组,然后就可以像现在一样工作。 –