我刚刚开始尝试使用仪表并做出反应,我做了基本的教程和一些在线的东西,现在我正在尝试创建自己的应用程序,但我似乎无法让它正常工作,这就是我所拥有的:
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;
},
});
我试图从他们在createContainer中拥有xxxx.find().fetch()
的教程中获取数据库中的特定客户配置文件,但这会带来配置文件表中的所有数据,这看起来风险很大。
目前,该应用程序只是说加载而没有其他事情发生。
详细的帮助将是值得赞赏的,因为我已经把头撞在墙上两天了!
答案 0 :(得分:0)
你的问题在这里
class App扩展了Component {
您需要使用
class About extends React.Component {
constructor(props) {
super(props);
this.state = {
};
}
....
}
我不确定extends React.Component
是否与extends Component
相同,但我认为您必须调用构造函数和super(props)来初始化所有React功能。
答案 1 :(得分: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
});
});
}