[英]meteor + react “Uncaught TypeError: Cannot read property 'data' of undefined”
[英]Meteor “TypeError: Cannot read property '0' of undefined”
我是新来的流星。
我想做的是在邀请某人加入该服务时向其发送电子邮件(完成),但我希望该电子邮件动态地包含邀请他们加入详细信息的用户。 这是我的代码:
Meteor.publish('profile', function() {
return Meteor.users.find(this.userId);
});
var emailData = {
existingUser: 'currentUser().profile.displayName',
existingOrganisation: 'currentUser().profile.organisation',
existingEmail: Meteor.users.emails[0].address
};
//Code taken from Meteor Docs to customise content of enrollment email
Accounts.emailTemplates.siteName = "Amendd";
Accounts.emailTemplates.from = "Amendd <no-reply@amendd.com>";
Accounts.emailTemplates.enrollAccount.subject = function (user) {
return "Welcome to Amendd";
};
Accounts.emailTemplates.enrollAccount.html = function (user, url) {
return SSR.render('enrollAccountEmail', emailData) + url;
};
其中enrollAccount.html是我的“ / private”文件夹中的单独文件。 在我的现存用户和现存的组织变量之后,我已将'-'放在适当的位置,同时我专注于使电子邮件字段正常工作。
在终端中保存并运行项目时出现的错误消息是
TypeError:无法读取未定义的属性“ 0””
它将我指向了现存电子邮件变量中的[0]。
谁能阐明我遇到的问题?
UPDATE
解决此问题的方法是在函数内移动emailData对象:
SSR.compileTemplate('enrollAccountEmail', Assets.getText('enrollAccountEmail.html'));
Accounts.emailTemplates.siteName = "Amendd";
Accounts.emailTemplates.from = "Amendd <no-reply@amendd.com>";
Accounts.emailTemplates.enrollAccount.subject = function (user) {
return "Welcome to Amendd , " + user.email;
};
Accounts.emailTemplates.enrollAccount.html = function (user, url) {
var emailData = {
existingUser: Meteor.user().profile.displayName,
existingOrganisation: Meteor.user().profile.organisation,
existingEmail: Meteor.user().emails[0].address
};
return SSR.render('enrollAccountEmail', emailData) + url;
};
我不相信currentUser()在服务器上工作。 尝试使用Meteor.user(),它将在发布功能之外的任何地方使用。
Meteor.user()。电子邮件[0]。地址
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.