3
我無法找到正確的方式,以便從列表視圖的行下的基於類的定義中觸發事件。以下是我走了這麼遠React native - ListView行中的綁定事件
class SampleApp extends React.Component {
constructor(props){
super(props)
this.state = {
dataSource: ds.cloneWithRows(this._partners()),
}
// this._click = this._click.bind(this);
}
_click() {
console.log('clicked');
}
_renderRow(rowData) {
return (<TouchableHighlight onPress={() => {this._click();}}>
<Text style={{ fontSize:18 }}>{rowData}</Text>
</TouchableHighlight>);
}
render() {
console.log('Partners: ', this._partners())
return (
<View style={styles.container}>
<ListView
dataSource={this.state.dataSource}
renderRow={ this._renderRow } />
</View>
);
}
}
this
內onPress
沒有提及反應成分。我該如何解決它?這是反應樂園的鏈接https://rnplay.org/apps/Xd-l3w
不起作用。它會給你'null不是一個對象' –
你使用的是哪個版本的RN? – Zidail
0.21。請檢查「反應播放」鏈接。請注意,我正在使用基於類的定義 –