I have to call a function when within the dialog I press the confirm button with the index where the dialog has started. It always sends me the last index of the for loop and not the one that corresponds
I copy the part of the code to which I refer:
JavaScript
x
88
88
1
<ul v-for="s in sortedArray" :key="s.key" >
2
3
{{s.key}}
4
<v-col cols="12">
5
<v-card
6
width="900"
7
color=#ECF0F1
8
>
9
<v-row>
10
<v-col cols="12">
11
<v-card-title><b>{{s.nombre}}</b></v-card-title>
12
13
</v-col>
14
15
16
</v-row>
17
<v-card-actions>
18
19
<v-row justify="center">
20
<v-col cols="12" >
21
<v-row justify="center">
22
<v-dialog v-model="dialogo_add_pr"
23
persistent
24
:retain-focus="false"
25
max-width="600px">
26
<template v-slot:activator="{on,attrs}">
27
<v-btn dark color="green" v-bind="attrs" v-on="on" >
28
<v-icon>mdi-plus</v-icon>
29
30
</v-btn>
31
</template>
32
<v-card>
33
<v-card-title>
34
<span class="text-h5">Añadir producto a seccion</span>
35
</v-card-title>
36
<v-card-text>
37
{{s.key}}
38
<v-row>
39
<v-col cols="12">
40
<v-select
41
:items="productos"
42
:item-text="'nombre'"
43
:item-value="'key'"
44
v-model="pr_ref"
45
:menu-props="{ top: true, offsetY: true }"
46
label="Producto"
47
></v-select>
48
49
</v-col>
50
</v-row>
51
</v-card-text>
52
<v-card-actions>
53
<v-spacer></v-spacer>
54
<v-btn text @click="cancela2" color="red">
55
Cancelar
56
</v-btn>
57
<v-btn text color="green" @click="addpr_seccion(pr_ref, s.key)" >
58
Añadir
59
</v-btn>
60
</v-card-actions>
61
</v-card>
62
63
</v-dialog>
64
</v-row>
65
66
</v-col>
67
<v-col cols="8"></v-col>
68
<v-col col="2">
69
70
<v-btn dark color="red" @click="eliminar_seccion(s.key)">
71
Eliminar
72
</v-btn>
73
74
</v-col>
75
<v-col col="2">
76
<v-btn dark color="blue" @click="editar_seccion(s.key)">
77
Editar
78
</v-btn>
79
</v-col>
80
</v-row>
81
82
</v-card-actions>
83
84
</v-card>
85
</v-col>
86
87
</ul>
88
On line 57:
JavaScript
1
4
1
<v-btn text color="green" @click="addpr_seccion(pr_ref, s.key)" >
2
Añadir
3
</v-btn>
4
s.key must contain the index from where the dialog was launched, but it contains the last index of the for loop.
I have tried a thousand things and read stackoverflow from top to bottom and I can’t find it, I’m learning VUE on my own
Advertisement
Answer
I was finally able to figure it out. Take the dialog out of the for loop, I have created a variable that tells me which element is the last selected, to which I give value from the button of each element.