2👍
Please have a look at the following code.
I took your code as a basis.
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
</head>
<body>
<div id="app">
<v-app>
<v-card>
<v-card-text>
<ul>
<li v-for="(ap, index) in ['1','2','3']" :key="index">
<v-select
:items="findelem()"
item-text="number"
item-value="number"
label="My Select"
@input="check_update_array"
></v-select>
</li>
</ul>
<p>
{{ elements }}
</p>
</v-card-text>
</v-card>
</v-app>v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>
<script>
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: function() {
return {
elements: []
}
},
methods: {
check_update_array(value) {
this.elements.push(value);
},
findelem(appi) {
return [{'number':'some element'},{'number':'another element'},{'number':'third element'}]
}
}
})
</script>
</body>
https://jsfiddle.net/ewatch/gn3eyxp2/
However some context was missing for me from your code regarding the “appi” parameter for the findelem function and the parameters “mark” and “VALUE” for the check_update_array function.
The function that is bind to the @input event receives the selected value as parameter already (see documentation here: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event).
I hope it helps.
Please let me know if you have any questions.
Best regards,
ewatch
2👍
Assuming you have a data named ‘selected_array’
data() {
return {
selected_array:[]
}
}
Now in your component, it should be look like this.
<v-card>
<v-card-text>
<ul>
<li v-for="ap in ['1','2','3']" :key="app">
<v-select
:items="findelem(appi)"
item-text="number"
item-value="number"
@chanage="check_update_array"
return-object
></v-select>
</li>
</ul>
</v-card-text>
</v-card>
Then in your check_update_array function, you code should look like this.
check_update_array(data){
let item_exist = false
this.selected_array.forEach(item => { // check if value exists.
if (item.value == data.value) {
item.mark = data.mark
item_exist = true
return
}
})
if (!item_exist) { // if not existing then append
this.selected_array.push(
{mark:value, value:value}
)
}
item_exist = false // reset value
}
Just make sure that your findelem(appi) is an array of objects containing mark and value elements