Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当我尝试从一个页面导航到另一个页面时,undefined不是一个对象(计算';(计算&#this.props.navigator.push';))_Javascript_Android_React Native - Fatal编程技术网

Javascript 当我尝试从一个页面导航到另一个页面时,undefined不是一个对象(计算';(计算&#this.props.navigator.push';))

Javascript 当我尝试从一个页面导航到另一个页面时,undefined不是一个对象(计算';(计算&#this.props.navigator.push';)),javascript,android,react-native,Javascript,Android,React Native,下面是示例代码,我正在尝试本地导航 我使用了react native init navigate来启动项目 然后我安装了 纱线添加反应自然-navigation@latest 代码在第一个屏幕上运行得非常完美,但当我调用showNextScreen函数时,它抛出了错误 未定义不是对象(评估'this.props.navigator.push')本机反应 import React,{Component}来自'React'; 进口{ 评估学, 样式表, 文本, 看法 }从“反应本机”; 从“reac

下面是示例代码,我正在尝试本地导航

我使用了react native init navigate来启动项目 然后我安装了

纱线添加反应自然-navigation@latest

代码在第一个屏幕上运行得非常完美,但当我调用showNextScreen函数时,它抛出了错误

未定义不是对象(评估'this.props.navigator.push')本机反应

import React,{Component}来自'React';
进口{
评估学,
样式表,
文本,
看法
}从“反应本机”;
从“react native Navigation”导入{Navigation};
从“./app/components/firstPage”导入第一页;
导出默认类导航扩展组件{
//用于移动到下一屏幕的函数
showNextScreen=()=>{
这个是.props.navigator.push({
屏幕:“首页”,
标题:“第一屏”
})
}
render(){
返回(
欢迎来到这里!
要开始,请编辑index.android.js
双击键盘上的R以重新加载,{'\n'}
摇动或按下开发菜单的菜单按钮
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
为内容辩护:“中心”,
对齐项目:“居中”,
背景颜色:“#F5FCFF”,
},
欢迎:{
尺寸:20,
textAlign:'中心',
差额:10,
},
说明:{
textAlign:'中心',
颜色:'#333333',
marginBottom:5,
},
});
AppRegistry.registerComponent('navigate',()=>navigate);

使用React本机导航,您必须以不同于最初的方式引导应用程序。本机导航不使用registerComponent设置,因为它是本机导航器


他们的文档中列出了完全设置的步骤。使用React Native Navigation,您必须以不同于最初的方式启动应用程序。本机导航不使用registerComponent设置,因为它是本机导航器


完全设置的步骤列在他们的文档中

正如您所说,您的代码在第一个屏幕上运行得非常完美,我很有信心您已经按照供应商网站上给出的配置说明进行了操作,因为如果不这样做,您的应用程序甚至不会运行。现在,您已经配置了startSingleScreenApp或StartTabbBaseDapp(不管是哪个),并且已经设置了屏幕(或选项卡)

navigator.push作为道具传递给您定义的屏幕,您可以从那里执行它。但是,this.props.navigator.push在应用程序范围内不可用,仅在定义的屏幕上可用。然后做什么?:根据需要将方法作为道具传递给组件子级

例如:

 navegarADetalleInstitucion = (institucion) => {
    console.log('[Navigating to institution]', institucion);
    this.props.navigator.push({
      screen: 'serviciosdominicanos.Servicios',
      title: 'Listado de Servicios',
      passProps: {
        institucion
      }
    });
  }

  renderInstituciones = () => {
    return this.state.instituciones.map(inst => <Institucion key={inst} institucion={inst} navegacion={() => this.navegarADetalleInstitucion(inst)} />)
  }
NAVEGARADETALLEINSTIUTION=(机构)=>{
console.log(“[导航到机构]”,institucion);
这个是.props.navigator.push({
屏幕:“serviciosdominicanos.Servicios”,
标题:“服务清单”,
通行证:{
研究所
}
});
}
RenderInstitutiones=()=>{
返回this.state.instituciones.map(inst=>this.navegarADetalleInstitucion(inst)}/>)
}
如果在子组件上定义了navegarADetalleInstitucion,并且我尝试从那里调用它,那么我将得到与您收到的错误完全相同的错误。但是,当我把它作为一个名为navegacion的道具发送时,当子组件执行navegacion时,它将正常工作


我知道这个问题已经很老了,但我希望它能帮助将来遇到这个错误的其他开发人员。

正如您所说,您的代码在第一个屏幕上运行得非常完美,我很有信心您已经按照供应商网站上给出的配置说明进行了操作,因为如果您不这样做,您的应用程序甚至不会运行。现在,您已经配置了startSingleScreenApp或StartTabbBaseDapp(不管是哪个),并且已经设置了屏幕(或选项卡)

navigator.push作为道具传递给您定义的屏幕,您可以从那里执行它。但是,this.props.navigator.push在应用程序范围内不可用,仅在定义的屏幕上可用。然后做什么?:根据需要将方法作为道具传递给组件子级

例如:

 navegarADetalleInstitucion = (institucion) => {
    console.log('[Navigating to institution]', institucion);
    this.props.navigator.push({
      screen: 'serviciosdominicanos.Servicios',
      title: 'Listado de Servicios',
      passProps: {
        institucion
      }
    });
  }

  renderInstituciones = () => {
    return this.state.instituciones.map(inst => <Institucion key={inst} institucion={inst} navegacion={() => this.navegarADetalleInstitucion(inst)} />)
  }
NAVEGARADETALLEINSTIUTION=(机构)=>{
console.log(“[导航到机构]”,institucion);
这个是.props.navigator.push({
屏幕:“serviciosdominicanos.Servicios”,
标题:“服务清单”,
通行证:{
研究所
}
});
}
RenderInstitutiones=()=>{
返回this.state.instituciones.map(inst=>this.navegarADetalleInstitucion(inst)}/>)
}
如果在子组件上定义了navegarADetalleInstitucion,并且我尝试从那里调用它,那么我将得到与您收到的错误完全相同的错误。但是,当我把它作为一个名为navegacion的道具发送时,当子组件执行navegacion时,它将正常工作


我知道这个问题已经很老了,但我希望它能帮助将来遇到这个错误的其他开发人员。

那么,根据您的参考,我的应用程序必须在选项卡式视图中吗link@devanshsadhotra你有两种方式开始。TabBased-SingleScreen-那么,根据您的参考,我的应用程序必须在选项卡式视图中运行吗link@devanshsadhotra你有两种方式开始。基于tab的单屏显示-