如何使用车把之外的变量#each scope?

时间:2017-10-09 12:53:25

标签: javascript handlebars.js

假设我将两个JSON对象传递给一个页面,然后我希望在把手中有一个嵌套的#each

orders = [-{id: 1}]
techs = [-{id: 2}]

{{#each orders as |order|}}
     {{order.id}}
     {{#each techs as |tech|}}
           {{tech.id}}
     {{/each}}        
{{/each}}

{{order.id}}会返回1,但{{tech.id}}不会返回任何内容。 有没有办法让第二个#each访问techs变量?

好的,这是解决方案:

orders = [-{id: 1}]
techs = [-{id: 2}]

{{#each orders as |order|}}
     {{order.id}}
     {{#each ../techs as |tech|}}
           {{tech.id}}
     {{/each}}        
{{/each}}

我刚刚向技术人员添加了../

0 个答案:

没有答案