【发布时间】:2015-10-08 18:46:38
【问题描述】:
我正在尝试使用数据集填充列表并使用辅助函数设置所选选项,该辅助函数将当前数据与另一个对象的数据进行比较(两个对象已链接)
我用静态变量制作了相同类型的列表填充: 玉-
select(name='status')
option(value='Newly Acquired' selected='{{isCurrentState "Newly Acquired"}}') Newly Acquired
option(value='Currently In Use' selected='{{isCurrentState "Currently In Use"}}') Currently In Use
option(value='Not In Use' selected='{{isCurrentState "Not In Use"}}') Not In Use
option(value='In Storage' selected='{{isCurrentState "In Storage"}}') In Storage
咖啡脚本-
"isCurrentState" : (state) ->
return @status == state
这使用一个助手 isCurrentState 将给定参数与我的其他代码链接到的同一对象匹配,因此我知道该部分有效
我要开始工作的代码是: 玉-
select.loca(name='location')
each locations
option(value='#{siteName}' selected='{{isCurrentLocation {{siteName}} }}') #{siteName}
咖啡脚本-
"isCurrentLocation": (location) ->
return @locate == location
所有其他部分都 100% 运行,但所选部分没有
我还尝试通过以下方式更改输入 selected='' 部分的方式:
- selected='{{isCurrentLocation "#{siteName}" }}'
- selected='{{isCurrentLocation "#{siteName} }}'
- selected='{{isCurrentLocation {{siteName}} }}'
- selected='#{isCurrentLocation "{{siteName}}" }'
- selected='#{isCurrentLocation {{siteName}} }'
- selected='#{isCurrentLocation #{siteName} }'
我正在尝试做的事情是否可能? 有没有更好的方法来实现这一点?
任何帮助将不胜感激
更新: 感谢@david-weldon 的快速回复,我已经尝试了一下,并意识到我并不清楚我在我的问题中想要完成什么。 我有一个模板“update_building”,它使用具有多个属性的参数(一个建筑对象)创建,其中一个是“定位”。
Locations 是另一个具有许多属性的对象,其中之一是“siteName”。 siteName == locate 之一,因此我需要从位置传递 siteName 以将其与当前建筑物的定位属性匹配
虽然它在我想使用它的上下文中不起作用,但它确实为我指明了一个我没有想到的方向。我正在考虑将父模板(建筑物)日期上下文作为参数移动到位置模板中,并在位置模板中使用它。这在普通的 HTML 空格键中很容易修复:
{{>locations parentDataContext/variable}}
jade 中的这种东西很容易解决这个问题
【问题讨论】:
标签: meteor coffeescript pug