我正在尝试创建以下内容:
我收到一组对象。每个对象由一个 id、一个选项和一个组名组成。我需要以一种方式输出数据,首先我有一个带有组名称属性值的复选框,然后是具有相同组属性的复选框列表。例如,假设我收到以下数据:
[
{id:1, text: 'Football', group: 'sport'}
{id:2, text: 'Basketball', group: 'sport'}
{id:3, text: 'Cookie', group: 'food'}
{id:4, text: 'Soup', group: 'food'}
]
所以输出应该如下:
<checkbox which when clicked should select all checkboxes belonging to this group>Sport</checkbox>
<checkbox>Football</checkbox>
<checkbox>Basketball</checkbox>
<checkbox which when clicked should select all checkboxes belonging to this group>Food</checkbox>
<checkbox>Cookie</checkbox>
<checkbox>Soup</checkbox>
到目前为止,我有以下内容:
export default {
data() {
return {
actionTypes: actionTypes,
relationTypes: relationTypes,
optionsList: [
{id:1, text: 'Football', group: 'sport'}
{id:2, text: 'Basketball', group: 'sport'}
{id:3, text: 'Cookie', group: 'food'}
{id:4, text: 'Soup', group: 'food'}
]
optionsGroupsList: ['Sport', 'Food'],
localValue: []
},
<link href="https://cdn.jsdelivr.net/npm/vuesax/dist/vuesax.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div
v-for="group in optionsGroupsList"
class="checkbox-group">
<vs-checkbox
:vs-value="group"
:key="group"
>
{{ group }}
</vs-checkbox>
<vs-checkbox
v-for="option in optionsList"
v-if="option.group === group"
:vs-value="option.id"
:key="option.id"
v-model="localValue"
>
{{ option.text }}
</vs-checkbox>
</div>
所以我确实收到了必要的输出,但我不知道如何使组复选框以选择属于它们的复选框的方式工作(属于该组)
我真的很感激任何想法,在此先感谢!
缥缈止盈
相关分类