我刚刚开始尝试meter和react,我在网上做了一些基本的教程和一些东西,现在我正在尝试创建我自己的应用程序,但我似乎无法让它正常工作,以下是我所拥有的:
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(),但这会带来配置文件表中的所有数据,这似乎相当有风险。
就目前而言,应用程序只是显示正在加载,没有发生其他事情。
感谢详细的帮助,因为我已经用头撞墙两天了!
发布于 2016-10-31 03:38:50
你的问题在这里
类App扩展了组件{
您需要使用
class About extends React.Component {
constructor(props) {
super(props);
this.state = {
};
}
....
}我不确定extends React.Component是否与extends Component相同,但我认为你必须调用构造函数和超级(Props)来初始化所有的React功能。
发布于 2016-10-31 23:31:26
您还需要通知服务器发布集合
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
});
});
}https://stackoverflow.com/questions/40322924
复制相似问题