2016-10-29 7 views
0

メーターを試して反応し始めたので、基本的なチュートリアルやオンラインのものをやってみましたが、今では自分のアプリケーションを作成しようとしていますが、正しく動作させるには、ここで私が持っているものです。Meteor-Ractデータが届かない

App.jsx:

import React, { Component, PropTypes } from 'react'; 
import ReactDOM from 'react-dom'; 
import { Meteor } from 'meteor/meteor'; 
import { createContainer } from 'meteor/react-meteor-data'; 

import AccountsUIWrapper from './AccountsUIWrapper.jsx'; 
import { Customers } from '../api/customers.js'; 

// App component - represents the whole app 
class App extends Component { 

    getProfile() { 
     if(Meteor.userId()){ 
      var cx = Meteor.call('customers.getProfile', Meteor.userId()); 

      if(cx && cx.account){ 
       console.log('FOUND'); 
       return (
        <div> 
         <div>Owner: {cx.owner}</div> 
         <div>Account: {cx.account}</div> 
         <div>Agents: {cx.agents}</div> 
        </div> 
       ) 
      }else{ 
       console.log('LOADING..'); 
       return (<div>Loading</div>); 
      } 
     }else{ 
      return (
       <div>Please sign in</div> 
      ) 
     } 
    } 

    render() { 
    return (
     <div className="container"> 
     <header> 
      <AccountsUIWrapper /> 
      <h1>Customer Portal</h1> 
     </header> 

     <ul> 
      {this.getProfile()} 
     </ul> 
     </div> 
    ); 
    } 
} 


App.propTypes = { 
    profile: PropTypes.array.isRequired, 
    currentUser: PropTypes.object, 
}; 

export default createContainer(() => { 
    return { 
    profile: [], 
    currentUser: Meteor.user(), 
    }; 
}, App); 

customers.js

import { Meteor } from 'meteor/meteor'; 
import { Mongo } from 'meteor/mongo'; 
import { check } from 'meteor/check'; 

export const Customers = new Mongo.Collection('customers'); 

Meteor.methods({ 
    'customers.getProfile'(userId) { 
    check(userId, String); 

    if (! this.userId) { 
     throw new Meteor.Error('not-authorized'); 
    } 

    const temp = Customers.findOne({owner: userId}); 
    return temp; 
    }, 
}); 

私は、データベースから特定の顧客プロファイルを取得しようとしています彼らが持っているチュートリアルxxxx.find().fetch()はcreateContainerにありますが、これはプロファイルテーブル内のすべてのデータをかなり危険に見せます。

そのまま、アプリは読み込みと言うだけで何も起こりません。

私は2日間壁に向かって頭を打っているので、詳細なヘルプをいただければ幸いです!

答えて

0

あなたの問題はここにある

アプリケーションはコンポーネントを拡張

クラス{

あなたはextends React.Componentextends Componentと同じであるかどうかわからない

class About extends React.Component { 
    constructor(props) { 
    super(props); 

    this.state = { 
    }; 

    } 
    .... 
} 

イムを使用する必要がありますが、私はあなたが呼び出すことがあると思いますすべてのReact機能を初期化するコンストラクタとスーパー(小道具)。

+0

を公開するサーバーを指示する必要があります。 – Mankind1023

+0

ああ、これらのファイルはどのフォルダにありますか? –

0

また、私は動作しませんでしたその怖いコレクション

if (Meteor.isServer) { 
    // This code only runs on the server 
    // Only publish data you want the current user to see 
    Meteor.publish(null, function() { 
    return Meteor.users.find(
     { 
     _id: this.userId 
     } { 
     fields: 
      Meteor.users.fieldsYouWantThemToSee 

     }); 
    }); 
} 
関連する問題