我有一个名为'isActive'的帮助器和一个名为'create'的模板..见下文
Template.create.isActive = function () {
return Meteor.user().profile.isActive;
};
Run Code Online (Sandbox Code Playgroud)
当我尝试运行此代码时,它在控制台中返回以下内容:"模板助手中的异常:TypeError:无法读取未定义的属性'profile'".
基本上我想从当前用户配置文件中提取'isActive'信息并将其返回到模板.知道为什么这不起作用吗?
//startup on server side:
Meteor.publish("userData", function() {
if (this.userId) {
return Meteor.users.find({_id: this.userId},
{fields: {'profile.isActive': 1}});
} else {
this.ready();
}
});
//startup on client side
Meteor.subscribe('userData');
//router
this.route('list', {
path: 'list',
waitOn : function () {
return Meteor.subscribe('userData');
},
data : function () {
return Meteor.users.findOne({_id: this.params._id});
},
action : function () {
if (this.ready()) {
this.render();
}
}
});
Run Code Online (Sandbox Code Playgroud) 在我收到此错误之前,我遇到了类似的问题:
模板助手中的异常:TypeError:无法读取未定义的属性"profile"
同样的事情再次发生,但是在第二个订单上,其中包含另一个用户配置文件信息(定义了第一个配置文件).我如何让它在{{#each orders}}中重新渲染?
当只有2个订单时,由于某种原因,似乎info.firstName,lastName和building被调用了3次...
在HTML中:
<template name="orderItem">
<section>
<form role="form" id="ordersList">
<div>
{{#each orders}}
<input type="text" name="name" value="{{info.firstName}} {{info.lastName}}">
{{/each}}
</div>
<div>
{{#each orders}}
<input type="text" name="building" value={{info.building}}>
{{/each}}
</div>
<div>
{{#each orders}}
<input type="text" name="featuredDish" value={{featuredDish}}>
{{/each}}
</div>
</form>
</section>
</template>
Run Code Online (Sandbox Code Playgroud)
在javascript中:
Template.orderItem.orders = function() {
var todaysDate = new Date();
return Orders.find({dateOrdered: {"$gte": todaysDate}});
};
Template.orderItem.info = function() {
var userId = this.userId;
var user = Meteor.users.findOne(userId)
var firstName = user.profile.firstName;
var lastName = user.profile.lastName;
var building …
Run Code Online (Sandbox Code Playgroud)