javascript - 在vuetify中切换组件时如何检查所有复选框?
问题描述
我想在更改 v-switch 时检查复选框列表。我所拥有的是:
这是开关组件,如果 selectAll 为真,我想检查所有复选框:
<v-switch style="padding-right:15px;" v-model="selectAll" @change="handleChanging">
</v-switch>
这是列表,每个项目之前都有一个复选框:
<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>
这里是js函数:
methods: {
handleChanging() {
if (this.selectAll === true) {
//here I want to check all checkboxes
} else {
//here to uncheck all
}
}
}
解决方案
你可以这样做:
handleChanging() {
if (this.selectAll === true) {
this.itemsEducators.forEach(x => x.checked = true);
} else {
this.itemsEducators.forEach(x => x.checked = false);
}
}
推荐阅读
- python - 如何使用python openpyxl删除公式并仅在单元格中保留值?
- xcode - 当我只有来自 make 输出的可执行文件时,如何创建 {ApplicationName}.app 包?
- visual-studio-code - 基于文件名的 VSCode 快捷方式
- java - 使用 java stringbuilder 的回文
- spring - 将弹簧迁移到弹簧引导控制器不起作用
- javascript - 为什么所有 redux reducer 函数都在运行时执行?
- python - Keras 中的回调异常 - Tensorflow 2.0 - Python
- c# - 使用 linq 获取具有特定对象属性的列表的一部分
- java - 如何将数据保存到房间?
- firebase - 使用 firestore 文档快照侦听器进行本地打印