Vuetify v-select 获取项目索引 [英] Vuetify v-select get item index

查看:85
本文介绍了Vuetify v-select 获取项目索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过不使用 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.

See it in action here

这篇关于Vuetify v-select 获取项目索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆