【问题标题】:userId vs Meteor.userId vs Meteor.userId()userId vs Meteor.userId vs Meteor.userId()
【发布时间】:2014-11-12 01:51:06
【问题描述】:

我对这段代码中的变量userId 感到困惑:

Posts.allow({
  insert: function(userId, doc) {
    // only allow posting if you are logged in
    return !! userId;
  }
});

docs 解释说Meteor.userId 返回一个函数,Meteor.userId() 返回一个字符串,但我不明白上面的userId 指的是哪一个。

【问题讨论】:

    标签: meteor meteor-accounts


    【解决方案1】:

    深入研究文档,似乎userId 只是allow()deny() 方法的第一个参数的默认名称。也可以这样写:

    Posts.allow({
      insert: function(theUser, doc) {
        // only allow posting if you are logged in
        return !! theUser;
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2014-08-10
      • 1970-01-01
      • 2012-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-19
      相关资源
      最近更新 更多