[英]Object #<Object> has no method 'User'
大家。 我的代碼和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');
}
});
});
運行流星應用程序時,出現以下錯誤:
=> 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);
您得到的錯誤是由於Meteor.User
中的大寫字母'u' Meteor.User
它應該是Meteor.user
。
但是,正如David Weldon指出的那樣,您需要在發布函數中使用Meteor.users.findOne(this.userId)
。
對於嘗試訪問Meteor.user()
時遇到錯誤Object #<Object> has no method 'user'
其他任何人,都Object #<Object> has no method 'user'
,請確保您具有基於帳戶的程序包。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.