I am dynamically populating the data and trying to display it.
I am getting the option id's of the Select elements, but I am not sure how do I get the parent element.
I tried to add hidden input but I cannot get value but I was not able to get the value(known issue)
new Vue({
el: "#app",
data() {
return {
variations : [
{
"id":1,
"variationName":"Material",
"created_at":"2020-08-20T16:23:18.000000Z",
"updated_at":"2020-08-20T16:23:18.000000Z",
"variant_options":[
{
"id":1,
"variants_id":1,
"variationOptionName":"Plastic",
"created_at":"2020-08-20T16:45:15.000000Z",
"updated_at":"2020-08-20T16:45:15.000000Z"
},
{
"id":2,
"variants_id":1,
"variationOptionName":"Wood",
"created_at":"2020-08-20T16:45:45.000000Z",
"updated_at":"2020-08-20T16:45:45.000000Z"
},
{
"id":3,
"variants_id":1,
"variationOptionName":"glass",
"created_at":"2020-08-20T16:46:23.000000Z",
"updated_at":"2020-08-20T16:46:23.000000Z"
},
{
"id":4,
"variants_id":1,
"variationOptionName":"pvc",
"created_at":"2020-08-20T16:47:15.000000Z",
"updated_at":"2020-08-20T16:47:15.000000Z"
},
{
"id":5,
"variants_id":1,
"variationOptionName":"unknown",
"created_at":"2020-08-20T16:47:58.000000Z",
"updated_at":"2020-08-20T16:47:58.000000Z"
}
]
},
{
"id":2,
"variationName":"color",
"created_at":"2020-08-20T16:25:14.000000Z",
"updated_at":"2020-08-20T16:25:14.000000Z",
"variant_options":[
]
},
{
"id":3,
"variationName":"type",
"created_at":"2020-08-20T16:25:45.000000Z",
"updated_at":"2020-08-20T16:25:45.000000Z",
"variant_options":[
{
"id":6,
"variants_id":3,
"variationOptionName":"working",
"created_at":"2020-08-20T16:48:44.000000Z",
"updated_at":"2020-08-20T16:48:44.000000Z"
}
]
}
],
variationOptions: [],
};
},
mounted: function () {
for (let i = 0; i < this.variations.length; i++) {
this.variationOptions.push({
values: [],
});
}
},
methods: {},
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<div>
<table class="table">
<thead>
<tr>
<td>Variation Name</td>
<td>Variation Values</td>
</tr>
</thead>
<tbody>
<tr v-for="(items,index) in variations">
<td>{{items.variationName}}</td>
<td>
<select multiple class="form-control" id="exampleFormControlSelect2" v-model="variationOptions[index]['values']">
<option v-for="(variationOptions,index) in items.variant_options" :key="variationOptions.id" :value="variationOptions.id">{{variationOptions.variationOptionName}}</option>
</select>
</td>
{{variationOptions}}
</tr>
</tbody>
</table>
</div>
</div>
Also I am getting the following error.
*Error in render: "TypeError: Cannot read property 'values' of undefined"*
Where am I wrong. I would appreciate if you could take a moment to explain
Update:
I have updated the values with item.id and getting the data as I expect.
But the format is
[ { "items": { "id": [] } }, { "items": { "id": [] } }, { "items": { "id": [] } } ]
How do I remove the items and id from the result.
variationOptionsinstead ofvariationsin the template<tr v-for="(items,index) in variations">