上一篇 实现了NavigatorIOS与ListView结合使用的方法

这篇文章介绍一下ListView里点击跳转到新视图的方法

先看效果

20180802095850

用法

NewsList.js

_onPress(rowData) {
  this.props.navigator.push({
    title: rowData,
    component: CNodeJSList,
    passProps: {
      name: rowData,
    }
  })
}

说明

  • 使用 this.props.navigator.push() 指定component 就可以跳转到下一个视图里了,如果想传值,可以用 passProps 属性,在下一个视图里使用 this.props.name 接收就可以了
  • 对于onPress里方法的调用,如果是以onPress={this._onPress}调用 _onPress方法,页面是不跳转的,需要绑定this,写法是:onPress={this._onPress.bind(this)} 但这样好像没法传值,所以要传值需要这样写:onPress={()=>{this._onPress(rowData)}} ,这样就没问题了,页面也可以跳转成功了

参考

源码:https://github.com/tomoya92/ITNews-React-Native

原文链接: https://chenyongze.github.io/2017/08/02/react-native-listview-forward/