简体   繁体   English

车把中的嵌套“每个”块

[英]Nested 'each' block in handlebars

Is there a way to achieve something like this:有没有办法实现这样的事情:

{{#each firstArray as |first|}}
  {{#each secondArray as |second|}}
      // this should be value of object from second array with key from first array
    {{second[first]}}  
  {{/each}}
{{/each}}

The lookup helper allows you to lookup first on second .lookup助手允许你查找firstsecond

{{lookup second first}}

http://handlebarsjs.com/builtin_helpers.html#lookup http://handlebarsjs.com/builtin_helpers.html#lookup

Nested each blocks are possible, you refer to the item from the parent array by using this .嵌套每个块都是可能的,您可以使用this引用父数组中的项目。 the initial each uses this because im using an array directly.初始每个都使用它,因为我直接使用数组。 if it were part of a json object, i would reference the key instead如果它是 json 对象的一部分,我会改为引用键

https://jsfiddle.net/93fj7nje/ https://jsfiddle.net/93fj7nje/

{{#each this}}
  <ul>
  {{#each this}}
    <li>{{this}}</li>
  {{/each}}
  </ul>
{{/each}}
{{#each column in App.MyController.getColumnValues}}
      {{view App.CountView rowBinding="first" columnBinding="second"}}

Please refer this pages请参考此页面

Page

Page 2 第2页

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

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