Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Meteor用户收集和Deps.autorun问题_Javascript_Meteor_Subscription - Fatal编程技术网

Javascript Meteor用户收集和Deps.autorun问题

Javascript Meteor用户收集和Deps.autorun问题,javascript,meteor,subscription,Javascript,Meteor,Subscription,我仍在努力理解如何将Meteor.users作为外键从另一个集合查询中访问。我知道默认情况下只发布当前用户,因此我在服务器上有一个发布 Meteor.publish('itemOwner', function(userId) { check(userId, String); var user = Meteor.users.find({id: userId}); return user; // return Meteor.users.find({id: userId}, { /

我仍在努力理解如何将Meteor.users作为外键从另一个集合查询中访问。我知道默认情况下只发布当前用户,因此我在服务器上有一个发布

Meteor.publish('itemOwner', function(userId) {
  check(userId, String);
  var user = Meteor.users.find({id: userId});
  return user;
  // return Meteor.users.find({id: userId}, {
  //   fields: {'profile': 1} });
});
然后我在客户端上有一个Deps.autorun

Deps.autorun(function () {
  var itemOwnerId = Session.get("itemOwnerID");
  if (itemOwnerId) {
    debugger
    var ID = Session.get("itemOwnerID");
    Meteor.subscribe('itemOwner', Session.get("itemOwnerID"));
  }
});
我在模式表单加载上设置会话ID,并通过调用ownerProfile助手(或尝试)在模板中显示它


现在,我可以在每个阶段跟踪用户ID,并看到它正确地传递给自动运行和助手。如果我在ownerProfile helper中的调试器和控制台中停止程序,放入Meteor.user.fetch({u id:“此处的id”}).fetch(),我将返回正确的用户。。但是,在处理程序本身中,Meteor.users.find返回null???我错过了什么?

我注意到了两种可能性

首先,在发布函数的find中缺少下划线

.find({id:userId})
应该是
.find({u id:userId})

但是,如果您在控制台中看到用户(而不是登录的用户),这可能不是问题所在

其次,如果您没有从
模板.showQuoteModalInner.ownerProfile
助手中看到用户,可能是因为您返回的是find()而不是findOne()


find()返回游标,而findOne()返回记录。如果要显示单个用户的属性,请尝试findOne()。

修复了这两个问题及其所有功能!!谢谢你。我已经看了好几天了,但没看到。
Template.showQuoteModalInner.helpers({
  getQuote: function () {
    // Get the quote ID from the session var
    var quote = Session.get("quoteID");
    if(quote) {
      debugger;
      var ID = quote.user._id;
      Session.set("itemOwnerID", quote.user._id);
      return quote;
    }
  },
  ownerProfile: function() {
    debugger;
    var quote = Session.get("quoteID");
    if(quote) {
      var ID = quote.user._id;
      var theUser = Meteor.users.find({_id: quote.user._id});
      return theUser; 
    };
  }
});