Quiero marcar una lista de casillas de verificación cuando cambie un interruptor en V. Lo que tengo es esto:
Este es un componente de cambio, si selectAll es verdadero, quiero marcar todas las casillas de verificación:
<v-switch style="padding-right:15px;" v-model="selectAll" @change="handleChanging"> </v-switch>Aquí está la lista, cada elemento tiene una casilla de verificación antes:
<v-list-item v-for="(item, index) in itemsEducators" :key="index"> <v-list-item-action> <v-checkbox :key="item.title" :input-value="item.checked"> </v-checkbox> </v-list-item-action> <v-list-item-content> <v-list-item-title>{{ item.title }}</v-list-item-title> <v-list-item-subtitle>{{ item.institution }} </v-list-item-subtitle> </v-list-item-content> </v-list-item>Una aquí es la función js:
methods: { handleChanging() { if (this.selectAll === true) { //here I want to check all checkboxes } else { //here to uncheck all } }}
Puedes hacerlo usando esto:
handleChanging() { if (this.selectAll === true) { this.itemsEducators.forEach(x => x.checked = true); } else { this.itemsEducators.forEach(x => x.checked = false); } }