I have a grouped checkbox whose data is populated via an API call. I want to write a VUE code such that when a user selects a checkbox I want to add an object to the array binding on the v-model of the checkbox input. I'll share the payload of the data being populated into the checkbox and my VUE and HTML code below in that order.
"data":[
{
"customerId":"046094",
"coreSystem":"symplusAM",
"accountId":"MMF046094001",
"fundName":"UNITED CAPITAL MONEY MARKET FUND"
},
{
"customerId":"046094",
"coreSystem":"symplusAM",
"accountId":"SIS046094001",
"fundName":"UNITED CAPITAL STAFF INVESTMENT SCHEME"
},
{
"customerId":"046094",
"coreSystem":"symplusAM",
"accountId":"EUROB046094001",
"fundName":"UNITED CAPITAL NIGERIAN EUROBOND FUND "
}
]
VUE Code:
<div style="padding-top:40px;" class="col s3">
<div class="input-field">
<h6 class="left-align">Select Portfolio Accounts</h6>
<template v-for="(item, key, index) in portfolioList">
<p>
<label>
<input v-model="selectedPortfolios[item]" :value="item" type="checkbox" class="filled-in" />
<span>
{{ item.fundName }}
</span>
</label>
</p>
</template>
</div>
</div>
What I want to achieve is that whenever a checkbox item is selected, I want to get these fields for that item "customerId":"046094","coreSystem":"symplusAM","accountId":"MMF046094001" and add it as an object into the array bounded to the checkbox group i.e. selectedPortfolios[item]. Please how do I achieve this in Vue.