gpt4 book ai didi

javascript - 对象 # 没有方法 'User'
转载 作者:行者123 更新时间:2023-11-28 07:53:33 25 4
gpt4 key购买 nike

大家。我的代码和 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;
});

库/router.js

Router.map(function() {
this.route('dashboardUsers', {
layoutTemplate: 'dashboardLayout',
path: "/dashboard/users",
waitOn: function() {
return Meteor.subscribe('getUsers');
}
});
});

当我运行meteor应用程序时,出现以下错误:

=> 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

最佳答案

如果您查看 Meteor.user 的文档,您会发现它在任何地方都可以工作,除了发布功能。你需要做的是:

var loggedInUser = Meteor.users.findOne(this.userId);

关于javascript - 对象 #<Object> 没有方法 'User',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26451579/

25 4 0