Javascript v-for内的Vuetify v-autocomplete onchange事件

Javascript v-for内的Vuetify v-autocomplete onchange事件,javascript,vue.js,vuetify.js,Javascript,Vue.js,Vuetify.js,我在中有一个下拉列表,用于为办公室列表中的每个办公室选择区域。 问题是,我不知道如何在updateRegion方法中传递索引值,以将当前选定的值与正确的办公区域相关联。 也许还有别的办法,但我不知道怎么做 以下是简化的代码: <template v-for="(office, index) in offices"> <v-flex xs12 class="mt-3" :key="index"> <v-card class="white--te

我在
中有一个
下拉列表,用于为办公室列表中的每个办公室选择区域。 问题是,我不知道如何在
updateRegion
方法中传递索引值,以将当前选定的值与正确的办公区域相关联。 也许还有别的办法,但我不知道怎么做

以下是简化的代码:

<template v-for="(office, index) in offices">
    <v-flex xs12 class="mt-3" :key="index">
        <v-card class="white--text">
            <v-card-text>
                <v-layout row wrap>
                    <v-flex xs12 sm4 pr-2>
                        <v-autocomplete
                            :value="office.region.id"
                            :items="regions"
                            :label="Region"
                            @change="updateRegion"
                        ></v-autocomplete>
                    </v-flex>
                </v-layout>
            </v-card-text>
        </v-card>
    </v-flex>
</template>

<script>
    methods: {
        updateRegion(value) {
            // how can I have here the index value?
        }
    }
</script>

方法:{
更新区域(值){
//这里怎么能有索引值?
}
}

如果我答对了,您希望在updateRegion方法中访问office索引和v-autocomplete中的选定值。如果我是对的,这应该像下面这样工作,通过将
office.regio.id
索引
传递给该方法

我还没来得及测试。如果不起作用,请告诉我

<template v-for="(office, index) in offices">
    <v-flex xs12 class="mt-3" :key="index">
        <v-card class="white--text">
            <v-card-text>
                <v-layout row wrap>
                    <v-flex xs12 sm4 pr-2>
                        <v-autocomplete
                            :value="office.region.id"
                            :items="regions"
                            :label="Region"
                            @change="updateRegion(office.region.id, index)"
                        ></v-autocomplete>
                    </v-flex>
                </v-layout>
            </v-card-text>
        </v-card>
    </v-flex>
</template>

<script>
    methods: {
        updateRegion(value, index) {

            // how can I have here the index value?
        }
    }
</script>

方法:{
更新区域(值、索引){
//这里怎么能有索引值?
}
}
尝试以下代码:

<template v-for="(office, index) in offices">
    <v-flex xs12 class="mt-3" :key="index">
        <v-card class="white--text">
            <v-card-text>
                <v-layout row wrap>
                    <v-flex xs12 sm4 pr-2>
                        <v-autocomplete
                            v-model="office.region.id"
                            :items="regions"
                            :label="Region"
                            @change="(event) => updateRegion(event, index)"
                        ></v-autocomplete>
                    </v-flex>
                </v-layout>
            </v-card-text>
        </v-card>
    </v-flex>
</template>

<script>
methods: {
    updateRegion(value, index) {
       console.log(value);
       console.log(index); 
        // how can I have here the index value?
    }
}
</script>

方法:{
更新区域(值、索引){
console.log(值);
控制台日志(索引);
//这里怎么能有索引值?
}
}

Hi lwolf,您正确理解了问题,感谢您的快速回复。不幸的是,该值为空,而是正确传递了索引。