Javascript 把手模板中另一个If语句中的If语句
这些都是我要传递给Handlebar模板的对象Javascript 把手模板中另一个If语句中的If语句,javascript,handlebars.js,template-engine,Javascript,Handlebars.js,Template Engine,这些都是我要传递给Handlebar模板的对象 self.template = template({ data: self.model, lang:self.lang, page:self.mainPage, subpage:self.param }); 然后在foreach循环中,我有一个if语句,其中我无法访问父上下文元素。模板中的代码和问题如下所示: {{#each data}} <h1>{{../subpage}}</h1> --&
self.template = template({ data: self.model, lang:self.lang, page:self.mainPage, subpage:self.param });
然后在foreach循环中,我有一个if语句,其中我无法访问父上下文元素。模板中的代码和问题如下所示:
{{#each data}}
<h1>{{../subpage}}</h1> --> This is giving me a subpage value
{{#if this.brand}}
{{#if ../subpage}}
<h1>WHY IS THIS NOT SHOWING?</h1> --> This is what i am trying to achieve
{{/if}}
{{/if}}
{{/each}}
{{#每个数据}
{{../subpage}}-->这给了我一个子页面值
{{{如果是这个.品牌}
{{{如果../子页面}
为什么不显示?-->这就是我想要达到的目标
{{/if}
{{/if}
{{/每个}}
有什么办法可以做到这一点吗?非常感谢您的所有回答/评论 {{{#如果this.brand}}
进入另一个级别的上下文,那么您必须跳转到父上下文,而不是一次,而是两次
因此,您的模板应该是:
{{#each data}}
<h1>{{../subpage}}</h1>
{{#if this.brand}}
{{#if ../../subpage}}
<h1>This shows now!</h1>
{{/if}}
{{/if}}
{{/each}}
下面是一个演示解决方案的JSFIDLE:
我希望这有帮助
[
{
brand: "Brand A",
otherFields: "here"
}
]