Meteor 访问数据库查询的内容

Meteor 访问数据库查询的内容,meteor,Meteor,我肯定错过了一些重要的东西,但这是我的问题。我有一个包含“标题”和“内容”字段的文档集合 当我导航到一个特定的url时 http://localhost:3000/document/33ea5676-4f8f-4fe4-99d5-fe094556933d 我从url抓取文档id,通过Session.set('docID',\u id)存储它,然后想显示文档的标题。我有一个模板: <template name='document'> <h2>My document i

我肯定错过了一些重要的东西,但这是我的问题。我有一个包含“标题”和“内容”字段的文档集合

当我导航到一个特定的url时

http://localhost:3000/document/33ea5676-4f8f-4fe4-99d5-fe094556933d
我从url抓取文档id,通过
Session.set('docID',\u id)
存储它,然后想显示文档的标题。我有一个模板:

<template name='document'>
  <h2>My document is called {{document.title}}</h2>
</template>
Template.document.document = function() {
  return Documents.findOne({'_id':Session.get('docID')});
}

<template name='document'>
  {{#with document}}
    <h2>My document is called {{title}}</h2>
  {{/with}}
</template>
但这不起作用:我收到一个错误,大致如下:

Cannot read property 'title' of undefined
当然,因为在访问字段之前,必须从数据库中检索文档。如果我打电话

Template.document.document().title 
从控制台中,我检索标题。我试着制作一个特定于标题的函数

Template.document.title = function() {
  doc = Documents.findOne({'_id':Session.get('docID')});
  return doc.title;
}
但这也存在同样的问题。在数据库检索条目和同时调用
doc.title
抛出错误之间似乎存在延迟


我一定忽略了一些基本的东西。谢谢

尝试在模板中使用“with”:

<template name='document'>
  <h2>My document is called {{document.title}}</h2>
</template>
Template.document.document = function() {
  return Documents.findOne({'_id':Session.get('docID')});
}

<template name='document'>
  {{#with document}}
    <h2>My document is called {{title}}</h2>
  {{/with}}
</template>
Template.document.document=函数(){
返回Documents.findOne({“u id”:Session.get('docID'))});
}
{{{有文件}
我的文档名为{{title}
{{/与}}
简短回答的副本:
退货单和单据标题