{
"data": {
"some": [],
"other": [],
"goes": [],
"workoutUnitLabels": [{
"groupLabel": "DISTANCE",
"selected": "",
"unitID": 2,
"unitLabel": "Meters"
}, {
"groupLabel": "DISTANCE",
"selected": "",
"unitID": 3,
"unitLabel": "Miles"
}, {
"groupLabel": "DISTANCE",
"selected": "",
"unitID": 4,
"unitLabel": "Yards"
}, {
"groupLabel": "TIME",
"selected": "selected",
"unitID": 5,
"unitLabel": "Time (hh:mm:ss)"
}, {
"groupLabel": "VELOCITY",
"selected": "",
"unitID": 6,
"unitLabel": "Velocity (m/s)"
}]
}
}
考虑到上面的数据集,我试图将其传递给一个handlebar模板,但无法找出使其正常工作所需的循环。以下是我希望构建的内容:
<select>
<optgroup label="DISTANCE">
<option value="2">Meters</option>
<option value="3">Miles</option>
<option value="4">Yards</option>
</optgroup>
<optgroup label="TIME">
<option value="5">Time (hh:mm:ss)</option>
</optgroup>
<optgroup label="VELOCITY">
<option value="6">Velocity (m/s</option>
</optgroup>
但这是我目前正在做的(注意
DISTANCE
<select>
<optgroup label="DISTANCE">
<option value="2">Meters</option>
</optgroup>
<optgroup label="DISTANCE">
<option value="3">Miles</option>
</optgroup>
<optgroup label="TIME">
<option value="5">Time (hh:mm:ss)</option>
</optgroup>
<optgroup label="VELOCITY">
<option value="6">Velocity (m/s)</option>
</optgroup>
</select>
{{#each .}}
<label>some label here <input type="text" name="somename" value="{{somevalue}}" /></label>
<select>
{{#workoutUnitLabels}}
<optgroup label="{{groupLabel}}">
<option value="{{unitID}}" {{selected}}>{{unitLabel}} ({{unitID}})</option>
</optgroup>
{{/workoutUnitLabels}}
</select>
{{/each}}
有什么建议我需要在这里换车吗?