"react-native-grid-view" 中的 TouchableOpacity 出现问题

Getting issue with TouchableOpacity in "react-native-grid-view"

我正在使用 react-native-grid-view 节点模块来列出我的项目,因为我编写了如下代码:

showPlayer(item) {
        Alert.alert("Sample", "showPlayer");
}

renderItem(item) {
        return <TouchableOpacity style={{alignItems:"center"}} onPress={this.showPlayer.bind(this, item)}>
            <ImageLoad
                placeholderSource = {require('../images/PlaceHolder.png')}
                style={styles.thumbnail}
                isShowActivity = {false}
                source={{uri: thumbnailObj.value}}
        />
        <Text style={styles.gridText}> {item.name}</Text>
    </TouchableOpacity>
  }

对于上面的代码,我得到了这个错误:

undefined is not an object (evaluating 'this.showPlayer.bind')

这与 react-native-grid-view 无关,您需要将其引用传递给 renderItem 函数

 renderItem(item, that) {
        return <TouchableOpacity style={{alignItems:"center"}} onPress={that.showPlayer.bind(this, item)}>
            <ImageLoad
                placeholderSource = {require('../images/PlaceHolder.png')}
                style={styles.thumbnail}
                isShowActivity = {false}
                source={{uri: thumbnailObj.value}}
        />
        <Text style={styles.gridText}> {item.name}</Text>
    </TouchableOpacity>
  }

render() {
    return (
    <View> {this.renderItem(item, this)} </View>
)}