【发布时间】:2019-02-07 16:26:44
【问题描述】:
我有类似这里的代码。我想将输入名称设置为之前每个循环中的@index。
我可以以某种方式访问@previousIndex 吗?或者我可以将输入分配给在第二个每个循环之前创建的某种组,该组将在其中设置所有输入名称?
我收到的数据:
questions:[
{
question:"How old are you?",
answers:[
'16',
'18',
'20',
'25',
'other'
]
},
{
question:"How many kids do you have?",
answers:[
'0',
'1',
'2',
'other'
]
}
]
hbs 代码:
{{#each questions}}
<li>
<h3 class='question'>{{this.question}}</h2>
<div class='flexbox'>
{{#each this.answers}}
<label class="container">
<input type='radio' name='{{@previousIndex}}' value='{{@index}}'>
<span class='checkmark'>{{this}}</span>
</label>
{{/each}}
</div>
</li>
{{/each}}
【问题讨论】:
-
也许这会对你有所帮助stackoverflow.com/questions/38696860/…
-
解决了吗?检查下面的答案?成功了吗?
-
我发表我自己的答案。
标签: javascript html node.js handlebars.js