相关疑难解决方法(0)

如何在Meteor中保存之前更改对象服务器端

我正在尝试在更新集合后运行某些插入语句.例如,如果用户将嵌入文档位置添加到其用户文档中,我还希望将该嵌入文档插入到单独的位置集合中.有没有办法在服务器端执行此操作,以确保操作运行?

meteor

5
推荐指数
0
解决办法
2139
查看次数

在Meteor.js中,为什么this.userId == undefined?

我正在通过阅读一本书来学习Meteor,现在我们想要insert()userId是当前登录的用户.

Template.categories.events({

    'keyup #add-category': function(e, t) {
        if(e.which == 13) {
          var catVal = String(e.target.value || "");
          if(catVal) {
            lists.insert({Category: catVal, owner: this.userId});
            console.log(this.userId);
            Session.set('adding_category',false);
          }
        }
    },
Run Code Online (Sandbox Code Playgroud)

但是this.userId未定义,所以insert()没有按预期工作.让这个工作缺少什么?

不知何故,它适用于下面的代码(userId已定义):

lists.allow({
    insert: function(userId, doc) {
      return adminUser(userId);
    },
    update: function(userId, docs, fields, modifier) {
      return adminUser(userId);
    },
    remove: function(userId, docs) {
      return adminUser(userId);
    }
});
Run Code Online (Sandbox Code Playgroud)

更新

为什么在服务器端,this.userId工作但不是Meteor.userId()

Meteor.publish("Categories", function() {
    return lists.find({owner:this.userId}, {fields:{Category:1}});
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery mongodb node.js meteor

4
推荐指数
1
解决办法
3348
查看次数

标签 统计

meteor ×2

javascript ×1

jquery ×1

mongodb ×1

node.js ×1