React native - ListView行中的Binding事件

Tha*_*ran 3 react-native

我无法找到正确的方法,以便从列表视图行下的基于类的定义中触发事件.这是我到目前为止所做的

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>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

this里面onPress没有提到反应成分.我该如何解决?这是反应游乐场链接https://rnplay.org/apps/Xd-l3w

Zid*_*ail 5

试试这个.

constructor(props){
  super(props)
  this.state = {
    dataSource: ds.cloneWithRows(this._partners()),
  }

  this._renderRow = this._renderRow.bind(this);
}
Run Code Online (Sandbox Code Playgroud)

_renderRow()不包含范围.重新绑定它可以解决问题.

onPress={this._click}也将工作,而不是把this._click另一个功能.

这是代码分支.