简体   繁体   English

为什么我得到'无法读取属性'推送'未定义'(React Native)?

[英]Why am I getting 'Cannot read property 'push' of undefined' (React Native)?

In my index.ios.js, I have the following: 在我的index.ios.js中,我有以下内容:

  renderScene(route, navigator){
    return <route.component navigator={navigator} {...route.passProps}/>
  }

and

render() {
    return (
      <Navigator
        initialRoute={{name: 'FirstPage', component: FirstPage}}
        renderScene={this.renderScene}
      />
    );
  }

then in my FirstPage.js, to navigate to the SecondPage.js: 然后在我的FirstPage.js中,导航到SecondPage.js:

  _navigate(){
    this.props.navigator.replace({
      component: SecondPage,
      name: 'SecondPage'
    })
  }

Then in my SecondPage.js, it just renders the component in a . 然后在我的SecondPage.js中,它只是渲染组件。 And in my ThirdPage.js: 在我的ThirdPage.js中:

  _rowPressed(){
    this.props.navigator.push({
      component: FourthPage,
      name: 'FourthPage',
    })
  }


  <TouchableHighlight
    onPress={() => this._rowPressed()}
  >
     <View>
          <Text>Go to FourthPage</Text>
     </View>
  </TouchableHighlight>

Then in my FourthPage.js, I simply have: 然后在我的FourthPage.js中,我只是:

  <View style={styles.container}>
    This is FourthPage.js
  </View>

I am getting the error from the ThirdPage.js, which says: 我从ThirdPage.js得到错误,其中说:

Cannot read property 'push' of undefined in _rowPressed()

and I cannot seem to figure out why, because the this.props.navigator.push worked fine for both .replace and .push, but now I am getting this error. 我似乎无法弄明白为什么,因为this.props.navigator.push对.replace和.push都很好,但现在我收到了这个错误。 Any guidance or insight would be appreciated. 任何指导或见解将不胜感激。 Thank you in advance. 先感谢您。

<TouchableHighlight
    onPress={this._rowPressed.bind(this)}//add this
  >
     <View>
          <Text>Go to FourthPage</Text>
     </View>
  </TouchableHighlight>

you may just need to bind the Component 您可能只需要绑定组件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我会收到 TypeError:无法读取未定义的 react-router-dom 的属性“push” - Why am I getting TypeError: Cannot read property 'push' of undefined react-router-dom 我收到一个错误:无法读取未定义的属性“推送” - I am getting an error: Cannot read property 'push' of undefined 为什么会出现“ TypeError:无法读取未定义的属性” props”(反应路由器,React-Redux)? - Why am I getting 'TypeError: Cannot read property 'props' of undefined' (react-router, React-Redux)? 为什么我在 React Table 中收到此错误 - 无法读取未定义的属性 &#39;col11bDataExpanded&#39; - ReactJS - Why I am getting this errors in React Table - Cannot read property 'col11bDataExpanded' of undefined - ReactJS 我为什么会收到TypeError:无法读取未定义的属性“现在” - Why am I getting TypeError: Cannot read property 'now' of undefined 为什么我在此 for 循环中无法读取未定义的属性“startsWith”? - Why am I getting Cannot read property 'startsWith' of undefined in this for loop? 为什么会出现“无法读取未定义的html属性”? - Why am I getting “Cannot read property of html undefined”? 为什么我越来越无法读取未定义错误的属性? - why I am getting, cannot read property of undefined error? 为什么在此示例中出现“无法读取未定义的属性&#39;文本&#39;”? - Why am I getting “Cannot read property 'text' of undefined” in this example? 为什么我收到“ TypeError:无法读取未定义的属性” length” - Why am I getting 'TypeError: Cannot read property 'length' of undefined'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM