Vuetify v-select 获取项目索引 [英] Vuetify v-select get item index
问题描述
有没有办法通过不使用 v-select 中的 v-model 来获取项目值...这是我的代码.
<v-选择:label="问题.名称":items="问题.答案"项目值=id"项目文本=名称"@change="addAnswer(i)"必需的></v-select></v-flex>
我不能使用 v-model
因为它是一个循环.我可以在问题的循环中传递 i
,但是 item-value 怎么样?
方法:
addAnswer(i){this.questionAnswer.push({问题编号:我,answerId: '这应该是答案 ID'})console.log(this.questionAnswer)}
如果您有任何想法如何做到这一点......这将是一个很大的帮助.谢谢.
@change="addAnswer"
会将选定的值传递给 addAnswer
方法.>
所以你不必传递索引.反正我做了一个例子来看看我的解决方案.它需要更多的代码才能完美,但我认为它可能对你有帮助.
is there a way to get the item-value by not using the v-model in v-select... Here is my code.
<v-flex xl4 lg4 md4 sm6 xs12 class="pa-2" v-for="(question, i) in questions" :key="i">
<v-select
:label="question.name"
:items="question.answers"
item-value="id"
item-text="name"
@change="addAnswer(i)"
required
></v-select>
</v-flex>
I can't used a v-model
since it is a loop. I can passed the i
in the loop for the question but how about the item-value?
Methods:
addAnswer(i){
this.questionAnswer.push({
questionId: i,
answerId: 'this should be answer Id'
})
console.log(this.questionAnswer)
}
If you have any idea how to do this... It would be a great help. Thanks.
The @change="addAnswer"
will pass to the addAnswer
method the selected value.
So you don't have to pass the index.Anyway i made an example to see my way of solution.It needs more code to be perfect,but i think it may help you.
这篇关于Vuetify v-select 获取项目索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!