一段时间以来,我一直在努力为特定用户显示用户配置文件,并且我取得了相当大的成功。我遇到标题错误的问题。
我发布了这样的学校收藏
Meteor.publish("schoolData", function () {
return Schools.find();
});
我的订阅看起来像这样
Meteor.subscribe('schoolData');
我的 HTML 看起来像这样
<template name="userProfile">
<title>My Profile</title>
<table>
<tr>
<td>User Name: </td>
<td>{{userName}}</td>
</tr>
<tr>
<td>First Name: </td>
<td>{{firstName}}</td>
</tr>
<tr>
<td>Last Name: </td>
<td>{{lastName}}</td>
</tr>
<tr>
<td>Registered E-mail: </td>
<td>{{email}}</td>
</tr>
<tr>
<td>Contact E-mail: </td>
<td>{{email}}</td>
</tr>
<tr>
<td>Phone Number: </td>
<td>{{phoneNumber}}</td>
</tr>
<tr>
<td>School: </td>
<td>{{schoolName}}</td>
</tr>
<tr>
<td>First year: </td>
<td>{{firstSchoolYear}}</td>
</tr>
<tr>
<td>Last year: </td>
<td>{{lastSchoolYear}}</td>
</tr>
<tr>
<td>Matriculated? </td>
<td>{{matriculated}}</td>
</tr>
<tr>
<td>House Name: </td>
<td>{{houseName}}</td>
</tr>
<tr>
<td>Country living in: </td>
<td>{{country}}</td>
</tr>
<tr>
<td>City living in: </td>
<td>{{cityOfResidence}}</td>
</tr>
<tr>
<td>Industry employed in: </td>
<td>{{emplIndustry}}</td>
</tr>
</table>
</template>
和 javascript 看起来像这样
Template.userProfile.helpers({
email: function() {return Meteor.user().emails[0].address},
userName: function () {return Meteor.user().username},
firstName: function () {return Meteor.user().profile.firstname},
lastName: function () {return Meteor.user().profile.lastname},
phoneNumber: function () {return Meteor.user().profile.phone},
schoolName: function () {return Schools.findOne(Meteor.user().profile.schoolName).name;},
firstSchoolYear: function () {return Meteor.user().profile.firstschoolyear},
lastSchoolYear: function () {return Meteor.user().profile.lastschoolyear},
matriculated: function () {return Meteor.user().profile.matriculated},
houseName: function () {return Meteor.user().profile.housename},
country: function () {return Meteor.user().profile.country},
cityOfResidence: function () {return Meteor.user().profile.cityofresidence},
emplIndustry: function () {return Meteor.user().profile.emplindustry},
signedUp: function () {return Meteor.user().profile.createdAt},
});
我似乎在模板助手中得到了错误异常:TypeError: Cannot read property 'name' of undefined 并且它来自 Schools 集合。有人可以帮我找出我的错误吗?