数据未暴露于来自流星发布的反应组件

时间:2016-04-20 22:56:31

标签: javascript meteor reactjs meteor-react

也许我在这里遗漏了一些东西,但是我没有从我的数据库中将数据传输到我的组件中。

我正在使用react和meteor(w / mantra),在服务器上使用simpleSchema / collection2。据我所知,我的发布/订阅设置正确。

我用咒语cli构建了一些东西。 (顺便说一句很棒) Heres是我的设置:

组件:(client / modules / components / sidebar_hubs.js)

import React from 'react';
const renderIfData = ( hubs ) => {
if ( hubs && hubs.length > 0 ) {
     return hubs.map( ( hub ) => {
      return <li key={ hub._id }>{ hub.name }</li>;
    });
} else {
return <p>No hubs yet!</p>;
}
};

const SidebarHubs = ({hubs}) => (

 <div>
     <h1> Hubs </h1>
     {hubs.length}
     <ul> { renderIfData( hubs ) } </ul>
  </div>
);

export default SidebarHubs;

容器(client / modules / containers / sidebar_hubs.js)

import {useDeps, composeAll, composeWithTracker, compose} from 'mantra-core';
import SidebarHubs from '../components/sidebar_hubs.js';


export const composer = ({context}, onData) => {

 const {Meteor, Collections} = context();
 const subscription = Meteor.subscribe( 'hubs' );

 if ( subscription.ready() ) {
   const hubs = Collections.Hubs.find().fetch();
   onData( null, { hubs } );
 }

};

 export const depsMapper = (context, actions) => ({
   context: () => context
 });

export default composeAll(
  composeWithTracker(composer),
  useDeps(depsMapper)
)(SidebarHubs);

公开:(服务器/出版物/ hubs.js)

 import {Hubs} from '/lib/collections';
 import {Meteor} from 'meteor/meteor';
 import {check} from 'meteor/check';

 export default function () {
   Meteor.publish('hubs', function () {
     return Hubs.find();
   });
 }

我在这里错过了什么?

1 个答案:

答案 0 :(得分:0)

这令人困惑,因为没有任何东西正在破坏......而且正在渲染组件,只是没有数据。

扔了几个console.logs,看起来我的容器甚至没有被运行。我觉得这很明显啊......在我的main_layout.js文件中。

@Service
public class MyServiceBImpl implements MyServiceB {

    @MyAnnotation("I can't get this value")
    public void doSomething() { /* ... */ }

}

为:

import SidebarHubs from '../components/sidebar_hubs.js';

现在就像魅力一样。良好的调试技巧有很长的路要走......