Meteor 流星-将翡翠助手传递到助手函数

Meteor 流星-将翡翠助手传递到助手函数,meteor,coffeescript,pug,Meteor,Coffeescript,Pug,我试图用数据集填充列表,并用一个助手函数设置所选选项,该函数将当前数据与另一个对象的数据进行比较(这两个对象是链接的) 我使用静态变量制作了相同类型的列表填充: 玉石- 咖啡脚本- "isCurrentState" : (state) -> return @status == state "isCurrentLocation": (location) -> return @locate == location 这使用一个helper isCurrent

我试图用数据集填充列表,并用一个助手函数设置所选选项,该函数将当前数据与另一个对象的数据进行比较(这两个对象是链接的)

我使用静态变量制作了相同类型的列表填充: 玉石-

咖啡脚本-

  "isCurrentState" : (state) ->
     return @status == state
  "isCurrentLocation": (location) ->
     return @locate == location
这使用一个helper isCurrentState将给定参数与我的其他代码链接到的同一个对象相匹配,这样我就知道该部分是有效的

我正在尝试的代码是: 玉-

咖啡脚本-

  "isCurrentState" : (state) ->
     return @status == state
  "isCurrentLocation": (location) ->
     return @locate == location
所有其他部件100%正常工作,但所选部件不正常

我还尝试通过以下方式更改输入selected=''部分的方式:

  • 所选=“{isCurrentLocation”#{siteName}}}”
  • 所选=“{isCurrentLocation”#{siteName}}”
  • 所选=“{isCurrentLocation{{siteName}}”
  • 所选=“#{isCurrentLocation”{{{siteName}}}”
  • 所选=“#{isCurrentLocation{{{siteName}}}”
  • 所选=“#{isCurrentLocation#{siteName}}”
我想做的事可能吗? 有没有更好的方法来实现这一点

任何帮助都将不胜感激

更新: 谢谢你的快速回复,我已经尝试了一下,并意识到我不太清楚我想在我的问题中实现什么。 我有一个模板“update_building”,它是用一个参数(一个building对象)创建的,该参数具有许多属性,其中一个属性是“locate”

Locations是另一个具有许多属性的对象,其中一个是“siteName”。其中一个siteName==locate,因此我需要从Locations传入siteName,以将其与当前建筑的locate属性相匹配

虽然它在我想使用的上下文中不起作用,但它确实为我指明了一个我没有想到的方向。我正在研究将父模板(建筑)日期上下文作为参数移动到位置模板中,并从位置模板中使用它。这在普通HTML空格栏中很容易修复,具有:

{{>位置parentDataContext/variable}

jade中类似的东西很容易解决这个问题 长话短说 您实际上不需要传递当前位置,因为助手应该知道它自己的上下文。下面是一个简单(已测试)的示例:

翡翠

template(name='myTemplate')
  select.location(name='location')
    each locations
      option(value=this selected=isCurrentLocation) #{this}
LOCATIONS = [
  'Newly Acquired'
  'Currently In Use'
  'Not In Use'
  'In Storage'
]

Template.myTemplate.helpers
  locations: LOCATIONS

  isCurrentLocation: ->
    @toString() is Template.instance().location.get()

Template.myTemplate.onCreated ->
  @location = new ReactiveVar LOCATIONS[1]
咖啡

template(name='myTemplate')
  select.location(name='location')
    each locations
      option(value=this selected=isCurrentLocation) #{this}
LOCATIONS = [
  'Newly Acquired'
  'Currently In Use'
  'Not In Use'
  'In Storage'
]

Template.myTemplate.helpers
  locations: LOCATIONS

  isCurrentLocation: ->
    @toString() is Template.instance().location.get()

Template.myTemplate.onCreated ->
  @location = new ReactiveVar LOCATIONS[1]

我进一步研究了DataContext,最后制作了将select填充到不同模板中的选项,并为该模板提供了一个帮助器,访问模板的父级数据上下文,并使用该上下文确定建筑保存在其中的位置,以便我可以将该选项设置为selected

玉石-

咖啡脚本-

Template.location_building_option.helpers
   'isSelected': ->
      parent = Template.parentData(1)
      buildSite = parent.locate
      return @siteName == buildSite
谢谢,你的回答极大地帮助我朝着正确的方向前进