首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从模板帮助流星/ mongodb访问minimongo

从模板帮助流星/ mongodb访问minimongo
EN

Stack Overflow用户
提问于 2015-04-21 17:13:27
回答 1查看 548关注 0票数 0

我试图访问我的产品收集在Minimongo在html页面。当我在我的浏览器控制台,我可以键入Products.findOne();,它将返回一个产品。

然而,当我试图从我的模板助手返回一个产品时,我就没有定义。有人在想吗?

代码语言:javascript
复制
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 

});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-21 21:30:32

简单的回答:对helper函数中的集合执行您需要做的任何修改,然后返回一个JS对象。例如,如果您的集合如下所示:

代码语言:javascript
复制
SomeColleciton
  _id
    type: String
  birthday:
    type: Date
  firstname:
    type: String
  lastname:
    type: String
  timezone:
    type: Integer

您可以执行以下操作来转换它

代码语言:javascript
复制
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}

});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29778919

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档