0

我使用react-native-grid-view节点模块中列出我的项目获取问题与TouchableOpacity,因为我写了如下代码:在“反应本地网视”

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')

回答

2

这不会发生反应,本地网视你需要传递给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> 
)}