I am sending a post request from vue, the vue form is created with v-for loop as it is an array of data objects. Within the data objects there is another set of objects with a field. How do i setup the data structure? And how do i pass the data with id into vue data structure since the for loop creates more than 1 object? Appreciate any help here! thank you!
<div v-for="(list, index) in lists.items" :key="list.id">
<div class="card">
<div class="card-header">
{{ list.title }}
</div>
<div class="card-body">
<div class="row">
<div class="col-sm">
Select quantity of item: <br>
<input type="number" placeholder="Quantity of item">
</div>
<div class="col-sm">
<div v-for="addon in list.addons">
Include addons: <br>
<input type="checkbox" :value="addon.id">
<label>{{ addon.name }}</label>
<input type="number" placeholder="Quantity of addon">
</div>
</div>
<div class="col-sm">
<input type="submit" class="btn btn-primary" value="Buy" @click.prevent="buy(index)">
</div>
</div>
</div>
</div>
</div>
I need to send
[
{ item_id: id },
{ quantity: quantity },
[
[
{ addon_id: id },
{ addon_quantity: quantity }
],
[
{ addon_id: id },
{ addon_quantity: quantity }
]
]
]
to back end. the addon array can contain a single object or multiple objects depending on whether they have been selected.