车把访问嵌套循环中的外部索引

Handlebars access outer index in nested loop

假设我有以下代码:

<div>
  {{#each questions}}
  <div id="question_{{@index}}">
    {{#each this.answers}}
    <div id="answer_{{???}}_{{@index}}">
      {{this}}
    </div>
    {{/each}}
  </div>
  {{/each}
</div>

如何在内部(答案)循环中访问外部循环的索引(问题索引)?本质上我想要 id 格式为 "answer_questionIndex_answerIndex"

在一些文档中发现了这一点

Block Parameters

New in Handlebars 3.0, it's possible to receive named parameters from supporting helpers.

{{#each users as |user userId|}}
  Id: {{userId}} Name: {{user.name}}
{{/each}}

In this particular example, user will have the same value as the current context and userId will have the index value for the iteration.

https://handlebarsjs.com/guide/block-helpers.html#hash-arguments