我有以下数据
multipleTypes = [
{"type": "radio", "label": "Cool people names","option": ["Ralgar", "Mozzy"]},
{"type": "checkbox", "label": "Cool phones", "option": ["android", "iphone"]}
{"type": "radio", "label": "Cool pets", "option": ["monster", "moose"]},
{"type": "checkbox", "label": "Cool places", "option": ["bar", "undercovers", "moon"]},
]
这里是模板
<script id="checkbox-template" type="text/x-handlebars-template">
<fieldset>
<legend>{{label}}</legend>
{{#each option}}
<label for="regularCheckbox">
<input type="checkbox" id="regularCheckbox" value="checkbox 1">
<span>{{this}}</span>
</label>
{{/each}}
</fieldset>
</script>
<script id="radio-template" type="text/x-handlebars-template">
<fieldset>
<legend>{{label}}</legend>
{{#each option}}
<label for="regularRadio">
<input type="radio" name="radios" id="regularRadio" value="radio 1">
<span>{{this}}</span>
</label>
{{/each}}
</fieldset>
</script>
我正在尝试查看对象列表并根据 type 属性呈现模板。这可能吗?
If else
模板内的效果不太好。