我试图访问我的产品收集在Minimongo在html页面。当我在我的浏览器控制台,我可以键入Products.findOne();,它将返回一个产品。
然而,当我试图从我的模板助手返回一个产品时,我就没有定义。有人在想吗?
Template.Tires.onRendered(function() {
console.log(Products.findOne());
//after I return a product item, I need to modify its properties manually after it has loaded into the client
});发布于 2015-04-21 21:30:32
简单的回答:对helper函数中的集合执行您需要做的任何修改,然后返回一个JS对象。例如,如果您的集合如下所示:
SomeColleciton
_id
type: String
birthday:
type: Date
firstname:
type: String
lastname:
type: String
timezone:
type: Integer您可以执行以下操作来转换它
Template.Tires.helpers({
user: function(userId) {
var u = SomeCollection.findOne(userId);
var age = calcAge(u.birthday);
var ifworkinghour = calcifworkinghour(u.timezone);
return {name: u.firstname + ' ' + u.lastname, age: age, workinghour: ifworkinghour}
});https://stackoverflow.com/questions/29778919
复制相似问题