我正在尝试使用react-native-meteor包将react-native和meteor结合起来。Meteor成功地发布了一个“dos”集合,我已经能够在web客户端上订阅它。然而,在遵循了react-native-meteor包的文档(使用createContainer)之后,我无法订阅;句柄是“永不就绪”。当使用来自Meteor的autopublish包时,数据会加载。
版本
Meteor 1.3.4.1
react-native: 0.28.0
react-native-meteor: 1.0.0-rc14index.ios.js
// @flow
'use strict'
import React, { Component } from 'react'
import {
AppRegistry,
StyleSheet,
View,
NavigatorIOS,
StatusBar,
Text,
} from 'react-native'
import Meteor, {
createContainer,
MeteorListView,
} from 'react-native-meteor'
Meteor.connect('ws://localhost:3000/websocket')
import GeoLocation from './app/GeoLocation'
import ConnectionInfoSubscription from './app/NetInfo'
import GridLayout from './app/GridLayout'
class DoCHANGE_0 extends Component {
renderRow(Do){
return(
<Text>{Do.joke}</Text>
)
}
render() {
const { doList, } = this.props
return (
<View style={styles.container}>
<StatusBar
barStyle="light-content"
/>
<NavigatorIOS
style = {styles.container}
barTintColor='#556270'
titleTextColor='#fff'
tintColor='#fff'
initialRoute={{
title: 'DoCHANGE',
component: GridLayout
}}/>
{!doList && <Text>Not ready with subscription</Text>}
<MeteorListView
collection="dos"
renderRow={this.renderRow}
enableEmptySections={true}
/>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex:1,
}
});
export default createContainer(params=>{
const handle = Meteor.subscribe('dos')
return {
doList: handle.ready(),
};
}, DoCHANGE_0)
AppRegistry.registerComponent('DoCHANGE_0', () => DoCHANGE_0);我发现过类似的示例,但它们通常不使用react-native-meteor包,而是使用ddpclient包。我是不是漏掉了什么明显的东西?任何见解都是非常感谢的!
编辑:
(Meteor) /server/publish.js
Meteor.publish("dos", function() {
//console.log(Dos.find().fetch())
return Dos.find();
})(Meteor) /both/collections.js
Dos = new Mongo.Collection('dos');使用来自Meteor的自动发布时的屏幕截图。doList句柄仍未就绪。但是MeteorList可以正确填充。
Screenshot iOS autopublish on
https://stackoverflow.com/questions/38170550
复制相似问题