在把手中查找助手 [英] Lookup helper in handlebars
本文介绍了在把手中查找助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
{
'我有一个'countries'对象,我将其作为Handlebars上下文的一部分传入: hk':{'name':'香港','someotherprop':'someothervalue'},
'us':{'name':'美国','someotherprop':'yetanothervalue'},
...
}
我想使用查找手把助手来查找来自countrycode'hk'的名称'Hong Kong'。
我可以得到以下对象:
{'name':'香港','someotherprop':'someothervalue'}
使用以下Handlebars指令
{{lookup ../countries countrycode}}
code>
但是我现在如何从这个对象中提取name属性?
解决方案
显然,可以使用子表达式语法来链接查找调用
{{lookup(looku p ../countries countrycode)'name'}}
I have a 'countries' object which I pass as part of the Handlebars context:
{
'hk': {'name': 'Hong Kong', 'someotherprop': 'someothervalue'},
'us': {'name': 'United States', 'someotherprop': 'yetanothervalue'},
...
}
I want to use the lookup Handlebar helper to find from the countrycode 'hk' the name 'Hong Kong'.
I can get the following object
{'name': 'Hong Kong', 'someotherprop': 'someothervalue'}
using the following Handlebars directive
{{lookup ../countries countrycode}}
but how do I now extract the name property from this object?
解决方案
Apparently one can chain lookup calls using the subexpression syntax
{{lookup (lookup ../countries countrycode) 'name'}}
这篇关于在把手中查找助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文