大家。我的代码和Meteor 0.9.4有问题
这是我的代码:
服务器/ publications.js
Meteor.publish('getUsers', function () {
var loggedInUser = Meteor.User();
if (Roles.userIsInRole(loggedInUser, ['admin'])) {
return Meteor.users.find({}, {fields: {
_id: 1,
emails: 1,
roles: 1
}});
}
this.stop();
return;
});
LIB / router.js
Router.map(function() {
this.route('dashboardUsers', {
layoutTemplate: 'dashboardLayout',
path: "/dashboard/users",
waitOn: function() {
return Meteor.subscribe('getUsers');
}
});
});
当我运行meteor app时,出现以下错误:
=> App running at: http://localhost:3000/
I20141019-18:21:50.827(4)? Exception from sub 8CRiG3Jmdv4mohPhd TypeError: Object #<Object> has no method 'User'
I20141019-18:21:50.949(4)? at null._handler (app/server/publications.js:3:31)
I20141019-18:21:50.950(4)? at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1594)
I20141019-18:21:50.950(4)? at _.extend._runHandler (packages/ddp/livedata_server.js:943)
I20141019-18:21:50.950(4)? at _.extend._startSubscription (packages/ddp/livedata_server.js:769)
I20141019-18:21:50.951(4)? at _.extend.protocol_handlers.sub (packages/ddp/livedata_server.js:582)
I20141019-18:21:50.951(4)? at packages/ddp/livedata_server.js:546
答案 0 :(得分:0)
如果您查看了Meteor.user的文档,除了发布函数之外,您将看到它在的所有位置都有效。你需要这样做:
var loggedInUser = Meteor.users.findOne(this.userId);
答案 1 :(得分:0)
你得到的错误是因为大写&#39; u&#39;在Meteor.User
中,它应该是Meteor.user
。
然而,正如David Weldon所指出的那样,你需要在发布功能中使用Meteor.users.findOne(this.userId)
。
对于在尝试访问Object #<Object> has no method 'user'
时遇到错误Meteor.user()
的其他任何人,请确保您拥有基于帐户的软件包。