【问题标题】:How Do I Access Document Fields From Meteor Spacebars #with Template Helper?如何从 Meteor Spacebars #with Template Helper 访问文档字段?
【发布时间】:2012-06-28 10:10:02
【问题描述】:

此代码应显示文档字段 first_name 和 last_name,但它会生成“未捕获的错误:未知帮助程序 'first_name'”错误:

# In Template.
{{#with doc}}
<p>{{first_name}} {{last_name}}</p>
{{/with}}

# Template 'doc' property.
_.extend Template.doc,
  doc: -> Docs.findOne {_id: Session.get 'doc_id'}

如果我将 #with 和 findOne() 替换为 #each 和 find() 效果很好:

# In Template.
{{#each doc}}
<p>{{first_name}} {{last_name}}</p>
{{/each}}

# Template 'doc' property.
_.extend Template.doc,
  doc: -> Docs.find {_id: Session.get 'doc_id'}

这篇文章建议#with 应该可以工作Turn a meteor method returning a single object into a context for handlebar

我正在使用 Meteor 0.3.7

【问题讨论】:

    标签: meteor coffeescript spacebars


    【解决方案1】:

    doc 需要成为结果中的一个键(请原谅我的 js,我已将其转换为咖啡,我不知道如何直接在咖啡中那么好)。不过,最好只使用直接引用。

    试试这个(使用 findOne):

    _.extend Template.doc,
    doc: ->
    doc: Docs.findOne(_id: Session.get("doc_id"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-15
      • 1970-01-01
      • 2014-08-11
      • 1970-01-01
      • 2020-06-17
      • 2015-08-18
      • 1970-01-01
      • 2023-01-01
      相关资源
      最近更新 更多