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