Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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 React Native:从一个类到另一个类获取数据_Javascript_Reactjs_Class_React Native_Reactive Programming - Fatal编程技术网

Javascript React Native:从一个类到另一个类获取数据

Javascript React Native:从一个类到另一个类获取数据,javascript,reactjs,class,react-native,reactive-programming,Javascript,Reactjs,Class,React Native,Reactive Programming,第一类 从“时刻”导入时刻; 从“/InfoScreen”导入InfoScreen; 导出默认类启动屏幕扩展React.Component{ 建造师(道具){ 超级(道具); 此.state={ 孤岛加载:是的, 数据源:null, 刷新:错误 }; } //当屏幕被拉下时,通过其int状态调用fresh _onRefresh=()=>{ this.setState({刷新:true}); this.componentDidMount()。然后(()=>{ this.setState({刷新:f

第一类

从“时刻”导入时刻;
从“/InfoScreen”导入InfoScreen;
导出默认类启动屏幕扩展React.Component{
建造师(道具){
超级(道具);
此.state={
孤岛加载:是的,
数据源:null,
刷新:错误
};
}
//当屏幕被拉下时,通过其int状态调用fresh
_onRefresh=()=>{
this.setState({刷新:true});
this.componentDidMount()。然后(()=>{
this.setState({刷新:false});
});
};
//从API获取数据
componentDidMount(){
返回取回(“https://launchlibrary.net/1.4/launch?mode=verbose")
.then(response=>response.json())
.然后(responseJson=>{
这是我的国家({
孤岛加载:false,
数据源:responseJson.com
});
})
.catch(错误=>{
console.log(错误);
});
}
//渲染屏幕
render(){
//刷新if语句
if(此.state.isLoading){
返回(

好的,我将尽我所能解释这一点。该应用程序基本上以图片中显示的“卡片”形式显示火箭发射的时间、地点等。我使用react native,我想做的是在有人点击touchableHighlight(火箭发射“卡片”)时这样做它把他们从一级带到二级。二级是任何火箭发射“卡”的信息所在用户点击显示。我遇到的问题是从用户按到class 2/info屏幕的特定火箭发射获取数据。我尝试导出获取名称、日期等的方法,但没有成功。

您只需像这样传递导航参数

import Location from "./LaunchingScreen.js";

export default class InfoScreen extends React.Component {
  render() {
    return (

        <View>
        <Text>hugig</Text>

        </View>



    );
  }
}
this.props.navigation.navigate("InfoScreen", {
              itemId: 86,
              otherParam: 'anything you want here',
            })
然后在另一个屏幕中使用这些参数,如下所示

import Location from "./LaunchingScreen.js";

export default class InfoScreen extends React.Component {
  render() {
    return (

        <View>
        <Text>hugig</Text>

        </View>



    );
  }
}
this.props.navigation.navigate("InfoScreen", {
              itemId: 86,
              otherParam: 'anything you want here',
            })

您可以了解有关传递参数的更多信息。

您在哪里安装这些组件?我猜您有一个
App
组件是对的?您使用的是哪个导航器?我正在使用react Nativigation,它们在App.js中file@NoeDuran你试过我的答案了吗?@HaiderAli刚回到家,我不试了,看看我怎么会做不到写了一本关于我有多感激的书,这个问题让这个项目停止了,伙计,你太棒了