访问数据时未定义流星用户

Meteor user is undefined when accessing data

本文关键字:流星 用户 未定义 数据 访问      更新时间:2023-09-26

>编辑:问题已解决。我最近更改了发布规则,导致电子邮件无法发布到客户端。

有一个问题:我正在尝试在提交表单时发送通知电子邮件。这是代码

var fl = Meteor.users.find({_id:owner});
console.log(fl);
var email = fl.emails[0].address;
var html = Blaze.toHTMLWithData(Template.new_assigned_task_email);
Meteor.call('sendEmail',
      email,
      "email@email.com",
      "You have a new task offer!",
      html);

变量所有者是用户 ID。 控制台.log(所有者) 返回正确的 ID,控制台.log(FL) 返回用户对象。但是,calling fl.emails[0].address给了我"类型错误:未定义不是一个对象(评估'fl.email[0]')"错误。

我错过了什么吗?

>Meteor.users.find返回游标,您需要将用户检索为 js 对象。

尝试:

var fl = Meteor.users.findOne({_id:owner});
// OR
var fl = Meteor.users.findOne(owner) 
console.log(fl);