2017-08-07 8 views
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> 
    ) 
} 

答えて

0

であなただけに必要な部分をレンダリングこの

renderListItem(item) { 
return (
    <TouchableNativeFeedback onPress={()=>{this._onPressListItem(item)}}> 
     <View style={{ height: 50, backgroundColor: 'red' }}> 
      <Text>{item.name}</Text> 
     </View> 
    </TouchableNativeFeedback> 
) 
} 

のような項目を押したときのTouchableNativeFeedbackを定義し、あなたがクリックされている特定の行を見つけることができ

コンソールで
onPressListItem(items) { 
console.log(items) 
} 

あなたは 試みは、これはあなたに

+0

を助けることができるかもしれ行に押され、その額面項目の値を取得する応答をありがとう、私はこのソリューションを参照の問題は、すべてのことです新しいListItemが作成される時刻onPressは、そのバインドのためだけに新しい関数を作成します。これを避けようとしています。 – JCRamires

+0

あなたはitems配列を渡す必要があるという点でmapを使うことができます。そして、それは今働いているものと同じように動作します。 –

関連する問題