<checkbox-group @change="checkboxChange">
<label class="uni-list-cell uni-list-cell-pd" v-for="item in items" :key="item.value">
<view>
<checkbox :value="item.value" :checked="item.checked" />
</view>
<view>{{item.name}}</view>
</label>
</checkbox-group>
The data variable from the checkbox is
items: [
{
value: 'USA',
name: 'American'
},
{
value: 'JPN',
name: 'Japan'
},
{
value: 'ENG',
name: 'England'
},
{
value: 'FRA',
name: 'France'
}
]
When check the box for selecting different countries, will get this value.
["JPN", "ENG"]
checkboxChange: function(e) {
var items = this.items,
values = e.detail.value;
console.log(values) #get value ["JPN", "ENG"]
}
But the desired result is Array of JSON Objects like below
new_items: [
{
value: 'JPN',
name: 'Japan'
},
{
value: 'ENG',
name: 'English'
}
]
How can I use this value ["JPN", "ENG"] to map with checkbox items to get new_items?
>Solution :
Try to bind the whole object to the value prop :
<checkbox :value="item" :checked="item.checked" />
