Meteor.js 1.0 - 涉及 Iron Router 和模板助手的数据上下文

Meteor.js 1.0 - Data context involving Iron Router and template helpers

我正在使用 Iron Router 将数据传递到我的模板:

@route 'singleProperty',
  path: '/properties/:_id'
  data: ->
    Properties.findOne(@params._id)
  controller: "SinglePropertyController"

在我的控制器中,我有我的模板等待发布必要的集合:

waitOn: ->
  [
    Meteor.subscribe "properties"
  ]

我遇到的问题是,当我尝试从助手内部访问 @data 时,它返回为 undefined:

Template.singleProperty.helpers
  currentProperty: ->
    console.log @data

就是说,当我在 Template.rendered 中 运行 相同的 console.log 时,我得到了我期望的结果(data 对象):

Template.singleProperty.rendered = ->
  console.log @data

我需要更改什么才能在 Template.helper 中访问 data

在您的模板辅助方法中试试这个: Template.currentData()

Template.instance()Meteor docs

中要阅读的关键内容

希望这对您有所帮助。