【问题标题】:Object #<Object> has no method 'User'对象 #<Object> 没有方法“用户”
【发布时间】:2014-10-19 14:35:45
【问题描述】:

每个人。我的代码和 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() 是小写的 u,而不是大写的 U。
  • 不是Meteor.user()吗?

标签: javascript object methods meteor


【解决方案1】:

如果您查看Meteor.user 的文档,您会发现它在任何地方都可以使用除了 发布函数。你需要做的:

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

【讨论】:

    【解决方案2】:

    您得到的错误是因为Meteor.User 中的大写“u”应该是Meteor.user

    但是,正如 David Weldon 指出的那样,您需要在发布函数中使用 Meteor.users.findOne(this.userId)

    对于在尝试访问 Meteor.user() 时遇到错误 Object #&lt;Object&gt; has no method 'user' 的任何其他人,请确保您拥有基于帐户的软件包。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-04
      • 2012-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-15
      • 1970-01-01
      相关资源
      最近更新 更多