简体   繁体   English

带子表达式的车把模板

[英]Handlebars template with subexpresion

I am having trouble trying to get a subexpression in handlebars. 我在尝试获取车把中的子表达式时遇到麻烦。 I have this object 我有这个对象

{
  vehicles:{
    air:"airplane",
    water:"boat",
    land:"cars\nvans",
  }
}

I have this helper 我有这个帮手

Handlebars.registerHelper('split', function(str, ch) {
    if (!str) return '';
    if (typeof ch !== 'string') ch = /\n/;
    return str.split(ch).map(function(splitted) {
    splitted.trim();
});
});

I would like to have an output like this 我想要这样的输出

air/airplane
water/boat
land/cars
land/vans

With this template 有了这个模板

{{#each vehicles}}
    {{#each (split this)}}
        {{../key}}/{{{this}}}
    {{/each}}
{{/each}}

I debugged and the split helpers get the values correctly, i think it has to be something with the scope of my this 我进行了调试, split帮助程序正确获取了值,我认为这一定与我的范围有关

Thank you very much 非常感谢你

很好地发现了我的问题,在嵌套的#each访问对象的key的方法不是../@key ,事实证明它应该是@../key

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM