Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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 使用createContainer将Meteor数据获取到React Native中的问题_Javascript_Meteor_Reactjs_React Native - Fatal编程技术网

Javascript 使用createContainer将Meteor数据获取到React Native中的问题

Javascript 使用createContainer将Meteor数据获取到React Native中的问题,javascript,meteor,reactjs,react-native,Javascript,Meteor,Reactjs,React Native,我似乎无法让createContainer处理React原生数据和Meteor数据。我目前正在使用该软件包和Meteor/React Native的最新版本。我已经查看了该软件包的信息和Meteor对createContainer的官方评论。我想首先,我不确定这个容器是如何工作的。它看起来像是包装了最后调用的组件,并在反应数据更改时更新它 我尝试过几种不同的方法,但下面是我目前正在使用的方法。我不确定createContainer是否被调用,因为我在控制台中没有从我的log语句中看到任何东西。我

我似乎无法让createContainer处理React原生数据和Meteor数据。我目前正在使用该软件包和Meteor/React Native的最新版本。我已经查看了该软件包的信息和Meteor对createContainer的官方评论。我想首先,我不确定这个容器是如何工作的。它看起来像是包装了最后调用的组件,并在反应数据更改时更新它

我尝试过几种不同的方法,但下面是我目前正在使用的方法。我不确定createContainer是否被调用,因为我在控制台中没有从我的log语句中看到任何东西。我也尝试过使用Meter.user()和Meteor.userId(),但没有成功。知道我做错了什么吗

'use strict';

import React, { Component } from 'react'
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';
import { loginToSpotify } from './react-native-spotify-auth'
import Meteor, { createContainer } from 'react-native-meteor'
//import { testComponent } from './component'

//TODO: openURL bug on iOS9 causes iOS to confirm before redirect: http://stackoverflow.com/questions/32312009/how-to-avoid-wants-to-open-dialog-triggered-by-openurl-in-ios-9-0
//May also want to look into using Universal  links

Meteor.connect('http://localhost:3000/websocket');//do this only once

class ReactNativeApp extends Component {
  constructor(props) {
    super(props);
    this.state = {
      access_token: null
    };
  }

  componentDidMount() {
    loginToSpotify();
  }

  render() {
    const { todosReady } = this.props;
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit index.ios.js
        </Text>
        <Text style={styles.instructions}>
          Press Cmd+R to reload,{'\n'}
          Cmd+D or shake for dev menu
        </Text>
        <Text>
          Hello {!todosReady && <Text>Not Ready</Text>}
        </Text>
      </View>
    );
  }
}

export default createContainer(params=>{
  const handle = Meteor.subscribe('todos');
  console.log('todos: ' + Meteor.collection('todos').find());
  return {
    todosReady: handle.ready()
  }
}, ReactNativeApp);



const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF'
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5
  }
});

AppRegistry.registerComponent('ReactNativeApp', () => ReactNativeApp);
“严格使用”;
从“React”导入React,{Component}
进口{
评估学,
样式表,
文本,
看法
}从“反应本机”;
从“./react native spotify auth”导入{logintospottify}
从“react native Meteor”导入Meteor,{createContainer}
//从“./component”导入{testComponent}
//TODO:iOS9上的openURL错误导致iOS在重定向前确认:http://stackoverflow.com/questions/32312009/how-to-avoid-wants-to-open-dialog-triggered-by-openurl-in-ios-9-0
//可能还想研究使用通用链接
流星连接http://localhost:3000/websocket');//只做一次
类ReactNativeApp扩展组件{
建造师(道具){
超级(道具);
此.state={
访问令牌:null
};
}
componentDidMount(){
loginToSpotify();
}
render(){
const{todosReady}=this.props;
返回(
欢迎来到这里!
要开始,请编辑index.ios.js
按Cmd+R重新加载,{'\n'}
用于开发菜单的Cmd+D或shake
你好{!todosReady&&NotReady}
);
}
}
导出默认createContainer(参数=>{
const handle=Meteor.subscribe('todos');
console.log('todos:'+Meteor.collection('todos').find());
返回{
todosReady:handle.ready()
}
},反应性PP);
const styles=StyleSheet.create({
容器:{
弹性:1,
为内容辩护:“中心”,
对齐项目:“居中”,
背景颜色:“#F5FCFF”
},
欢迎:{
尺寸:20,
textAlign:'中心',
差额:10
},
说明:{
textAlign:'中心',
颜色:'#333333',
marginBottom:5
}
});
AppRegistry.registerComponent('ReactNativeApp',()=>ReactNativeApp);

您能在控制台中看到连接到应用程序的meteor吗?您不应该在Meteor.connect中再使用http,而应该使用ws://localhost:3000/websocket

  • 确保您的meteor应用程序正在运行
  • 使用本地计算机的IP,不要使用本地主机。如果您使用移动设备作为模拟器,这很好。在路由器中连接并使用您的机器语言
  • 如需了解更多信息,请按此操作