流星:如何使用对象名称,包括空格键中的破折号 [英] Meteor: How to use object names including dashes in Spacebars
问题描述
在任何地方都找不到答案,但是也许你们中的一个知道答案.
Didn't find the answer anywhere, but maybe one of you knows it.
我正在从http.call('GET')取回数据,我可以在 空格键,如
I'm getting back data from http.call('GET'), I can use the data correctly in Spacebars like
{{anydata.specificdata}}
但没有机会使用带有破折号之类的对象名称的数据
but have no chance to use data w/ object names containing dashes like
{{anydata.specific-data}}
我尝试了
{{anydata.'specific-data'}}
,但这也不起作用. 在检索许多不同的数据时,我想避免为每个包含破折号的字段创建帮助程序.
, but this does not work either. As I'm retrieving a lot of different data I would like to avoid to create helpers for every field containing dashes.
有人知道我该如何处理
{{anydata.specific-data}?
感谢您提供帮助的答案.
Thanks for any answer that helps.
玩得开心!
推荐答案
I found the answer on a meteor form: https://forums.meteor.com/t/dash-character-in-spacebars/2885
我遇到了类似的问题.我有一个JSON对象,变量名称中带有破折号.为了用破折号调用对象,请执行以下操作:
I ran into a similar problem. I had a json object with a dash in a the variable name. In order to call an object with a dash, the following is done:
{{some.json.object.[with-a-dash]}}
注意.在方括号之前,并且在短划线命名项目周围没有引号(单引号或双引号).
Note the . before the open bracket and no quotes (single or double) around the dash named item.
这篇关于流星:如何使用对象名称,包括空格键中的破折号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!