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}}”
{{>位置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
谢谢,你的回答极大地帮助我朝着正确的方向前进