【发布时间】:2014-11-22 12:43:31
【问题描述】:
一段时间以来,我一直在努力为特定用户显示用户个人资料,但我取得了相当大的成功。我遇到标题错误的问题。
我发布这样的学校收藏
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:无法读取未定义的属性“名称” 它符合这是来自学校的收藏。 谁能帮我找出我的错误。
【问题讨论】: