Javascript 把手在嵌套循环中访问外部索引
假设我有以下代码:Javascript 把手在嵌套循环中访问外部索引,javascript,express,handlebars.js,express-handlebars,Javascript,Express,Handlebars.js,Express Handlebars,假设我有以下代码: <div> {{#each questions}} <div id="question_{{@index}}"> {{#each this.answers}} <div id="answer_{{???}}_{{@index}}"> {{this}} </div> {{/each}} </div> {{/each} </div> {{{每个问
<div>
{{#each questions}}
<div id="question_{{@index}}">
{{#each this.answers}}
<div id="answer_{{???}}_{{@index}}">
{{this}}
</div>
{{/each}}
</div>
{{/each}
</div>
{{{每个问题}
{{{#每个人都这样回答}
{{this}}
{{/每个}}
{{/每个}
如何访问内部(答案)循环内部的外部循环索引(问题索引)?基本上,我想要
id
的格式为“answer\u questionIndex\u answerIndex”
在一些文档中找到了这种深度
块参数
Handlebars 3.0中的新功能,可以从支持助手处接收命名参数
在这个特定的示例中,user将具有与当前上下文相同的值,userId将具有迭代的索引值
我想说的是:从开始学习如何根据需要获取索引或键,然后再结合起来。然而,我认为这已经不可能了,在呈现数据之前,你可能需要进行一些数据操作——将问题的索引放在答案或问题中,因为我花了太多时间浏览文档和谷歌搜索什么也没找到,但这太完美了!非常感谢
{{#each users as |user userId|}}
Id: {{userId}} Name: {{user.name}}
{{/each}}