我刚开始尝试使用仪表并做出反应,我在网上做了基本教程和一些东西,现在我正在尝试创建自己的应用程序,但我似乎无法让它正常工作,这就是我所拥有的:
应用程序.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);
客户.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 中的教程中,但这会在配置文件表中引入所有数据,这似乎相当冒险。
就目前而言,该应用程序只是说正在加载,没有其他任何事情发生。
由于我已经将头撞在墙上两天了,因此将不胜感激详细的帮助!