簡體   English   中英

如何使用外部#each中的@index作為內部#each在Handlebars模板中的數組鍵

[英]How to use @index from outer #each as array key in inner #each in Handlebars template

當我具有傳遞給Handlebars模板的數據結構時:

{ a: ['name 1'], b: [[1,2,3]] }

我有以下循環:

{{#each a}}
  Hello, {{this}}!
  Your scores are:
  {{#each ../b[@index_of_a]}}
    {{this}}
  {{/each}}
{{/each}}

如何使用循環{{#each a}}當前元素索引(將其命名為XXX以獲得數組b元素: b[XXX]嗎?

如果您使用的是最新版本的Handlebars庫,則可以使用內置的查找幫助器來實現。

{{#each a}}
  Hello, {{this}}!
  {{#each (lookup ../b @index)}}
    {{this}}
  {{/each}}
{{/each}}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM