且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Handlebars.js:如何访问每个嵌套的父索引?

更新时间:2023-01-08 15:32:41

示例中存在语法错误。正确的语法是 {{@ .. / index}}



我们正在寻找可以在未来版本的语言中支持这些参数的自定义命名,因此更易于处理。
https://github.com/wycats/handlebars.js/issues/907


How to access parent @index value in each-loop?

Tried the following:

{{#each company}}
{{#each employee}}
  {{../@index}} // how to access company index here?
{{/each}}
{{/each}}

This results to an error:

Expecting 'ID', got 'DATA'

There is a syntax error in the example. The correct syntax is {{@../index}}.

We are looking at ways that we can support custom naming of these parameters in future versions of the language so this is easier to deal with. https://github.com/wycats/handlebars.js/issues/907