英文:
Vuetify: v-select get item AND another value from v-for loop
问题
我是你的中文翻译,以下是你要翻译的部分:
"Vuetify3 newbie here.
I have a table which is filled with v-for for some models. Each row has a v-select that need to fire an event when changed. Something like this:
If leave function in @update:modelValue="changeStatus"
without any parameters, I can get access to selected value in one v-select.
But how I can get selected value
AND id
of current row simultaneously?
I was thinking about something like @update:modelValue="changeStatus(item, payout.id)"
. But of course it doesn't work."
英文:
Vuetify3 newbie here.
I have a table which is filled with v-for for some models. Each row has a v-select that need to fire an event when changed. Something like this:
<tr v-for="payout in payouts" :key="payout.id">
<td>{{ payout.username }}</td>
<td>
<v-select
v-model="payout.status"
@update:modelValue="changeStatus"
:items="['On', 'Off']"
>
</v-select>
</td>
</tr>
If leave function in @update:modelValue="changeStatus"
without any parameters, I can get access to selected value in one v-select.
But how I can get selected value
AND id
of current row simultaneously?
I was thinking about something like @update:modelValue="changeStatus(item, payout.id)"
. But of course it doesn't work .
答案1
得分: 2
"Instead of calling changeStatus
directly, I would wrap it in a callback which dispatches the update:modelValue
argument AND payout.id
:
<tr v-for="payout in payouts" :key="payout.id">
<td>
<v-select @update:modelValue="val => changeStatus(val, payout.id)">
</td>
</tr>
I omitted some code to make it simpler to grasp."
英文:
Instead of calling changeStatus
directly, I would wrap it in a callback which dispatch update:modelValue
argument AND payout.id
:
<tr v-for="payout in payouts" :key="payout.id">
<td>
<v-select @update:modelValue="val => changeStatus(val, payout.id)">
</td>
</tr>
I omitted some code to make it simpler to grasp.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论