我在从父循环/每个循环获取值时遇到问题。我该怎么做?
我正在循环浏览一些问题,然后循环浏览一些答案。在每个答案上,我想添加问题 ID..
JSON:
{
"questions": [
{
"id": 1,
"answers": [
...
...
...
]
}
]
}
和 Assemble.io 嵌套循环/每个
{{#forEach questions}}
<h2>{{id}}</h2>
<ul>
{{#forEach this.answers}}
<li>
<input type="radio" name="{{id}}" id="{{id}}-{{index}}"/>
</li>
{{/forEach}}
</ul>
{{/forEach}}
你知道我如何从父循环/每个循环中获取 ID 吗?
提前谢谢你...:-)
最佳答案
在 Handlebars 中,您可以使用 parent accessor syntax ../
{{#forEach questions}}
<h2>{{id}}</h2>
<ul>
{{#forEach this.answers}}
<li>
<input type="radio" name="{{../id}}" id="{{../id}}-{{index}}"/>
</li>
{{/forEach}}
</ul>
{{/forEach}}
关于html - 组装(模板): Get parent value from within nested each block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27964122/