0
ListView
の項目の行にタップを処理しようとしていますが、試してみると少し違う方法で失敗します。`TouchableOpacity`のデータで` onPress`コールバックを得る方法
私はrenderRow
の機能を持っています。これはListView.renderRow
に提供されています。ここでは私がやりたい:
renderRow(rowData) {
return (
<TouchableOpacity onPress= {() => this.tapRow(rowData) }>
<View style={{margin: 5, backgroundColor: "#EEE" }}>
<Text>{rowData.text}</Text>
</View>
</TouchableOpacity>
)
}
そして、私のtapRow
関数である:これはエラー_this3.tapRow is not a function ... _this3.tapRow is undefined
になり
tapRow(rowData) {
console.log("Tapped Row: " + rowData.id)
}
。
私はまた、this.tapRow = this.tapRow.bind(this)
をコンストラクタに追加しようとしましたが、それは役に立ちません。
テストの場合は、onPress={this.tapRow}
も実行しました。これはエラーを引き起こすことはありませんが、関数は呼び出されません(私は確認するために単純なconsole.logを行います)
onPress
で呼び出される関数を取得して引数を与えますか?
はtapRow、tapRow =(rowData)=> { はconsole.log( "TEST")でこれを行うことを試みます。 } –
@GaneshCaudaこれは私が試したことであり、もう一度やり直しました。 '_this3.tapRow'の同じ問題は未定義です。 –
ああ、onpressはこれをやろうとします。onPress = {()=> this.tapRow({rowData})} –