Currently, I am facing a challenge with restructuring an array in Vue.js. I am able to log the values within my method and push them into an array, but I'm struggling to format the array as required.
The desired structure of the array should be like this:
{ "123" :
[
{ "item":"B-24", "new_date":"2022-11-30" },
]
}
If anyone has any suggestions on how to properly format the array within the method call, it would be greatly appreciated.
var vm =
new Vue({
el: "#app",
props: {
},
data: {
testing_dates:['2021-11-29', '2021-11-30'],
cat_id: [123]
},
methods: {
testChange(event, id){
item = "B-24";
console.log(event.target.value);
console.log(id);
var new_array = new Array(); //create an empty array
new_array.push(item);
new_array.push(event.target.value);
new_array.push(id);
},
},
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<li>Category ID: {{ cat_id }}</li>
<li style="list-style: none;">
<select style="width: auto;" @change="testChange($event, cat_id)">
<option selected disabled>Options</option>
<option v-for="date in testing_dates" :value="date">{{ date }}</option>
</select>
</li>
</div>