element-ui 里面el-checkbox多选框,实现全选单选
data里面定义了
data:[],
actionids:[],//选择的那个actionid
num1:0,//没选择的计数
num2:0,//选中的计数
checkAllBig: [],
checkAll:[],
checkOne:[],
获取所有数据:
this.data=res.data;
for(var i=0;i<this.data.length;i++){//遍历选择的内容
if(this.data[i].ischecked==1){
this.checkAllBig.push(this.data[i].affairtypeid)
}
for(var j=0;j<this.data[i].eventtype.length;j++){
if(this.data[i].eventtype[j].ischecked==1){
this.checkAll.push(this.data[i].eventtype[j].eventtypeid)
}
for(var k=0;k<this.data[i].eventtype[j].operation.length;k++){
if(this.data[i].eventtype[j].operation[k].ischecked==1){
this.checkOne.push(this.data[i].eventtype[j].operation[k].actionid);}
}
}
}
<div class="checkbox-table" v-for="(item,indexkey) in data">
<template>
<el-checkbox class="check1" v-model="checkAllBig" :label="item.affairtypeid" @change="handleCheckedCitiesChange(1,indexkey)">{{item.affairtypename}}{{item.ischecked}}</el-checkbox>
<div v-for="(list,index2) in item.eventtype" class="line-check" :key="list.eventtypeid">
<el-checkbox class="check2" @change="handleCheckedCitiesChange(2,indexkey,index2)" v-model="checkAll" :label="list.eventtypeid" v-bind:style="{ 'float':list.operation.length>0?'left':'none'}">{{list.eventtypename}}{{list.ischecked}}</el-checkbox>
<el-checkbox-group v-model="checkOne" class="checkGroup" >
<el-checkbox v-for="(operate,index1) in list.operation" :label="operate.actionid" :key="operate.actionid" @change="handleCheckedCitiesChange(3,indexkey,index2,index1)">{{operate.actionname}}{{operate.ischecked}}</el-checkbox>
</el-checkbox-group>
</div>
</template>
</div>
handleCheckedCitiesChange(type,a=0,b=0,c=0) {//多选框
if(type==1){//最高级全选
this.actionids=[];
if(this.data[a].ischecked==1){
this.data[a].ischecked=0;
for(var i=0;i<this.data[a].eventtype.length;i++){
this.checkAll=this.checkAll.map(res=>{
if(res!=this.data[a].eventtype[i].eventtypeid){return res}
});
for(var j=0;j<this.data[a].eventtype[i].operation.length;j++){
this.checkOne=this.checkOne.map(res=>{
if(res!=this.data[a].eventtype[i].operation[j].actionid){return res;}
});
}
}
}else{
this.data[a].ischecked=1;
for(var i=0;i<this.data[a].eventtype.length;i++){
this.checkAll.push(this.data[a].eventtype[i].eventtypeid);
for(var j=0;j<this.data[a].eventtype[i].operation.length;j++){
this.checkOne.push(this.data[a].eventtype[i].operation[j].actionid);
this.actionids.push(this.data[a].eventtype[i].operation[j].actionid)
}
}
}
this.api(this.data[a].ischecked);//调用接口把选择的传过去
}else if(type ==2){//第二级全选
this.actionids=[];
this.data[a].eventtype[b].ischecked=this.data[a].eventtype[b].ischecked==1?0:1;
for(var i=0;i<this.data[a].eventtype[b].operation.length;i++){
if(this.data[a].eventtype[b].ischecked==1){
this.checkOne.push(this.data[a].eventtype[b].operation[i].actionid);
this.$set(this.data[a].eventtype[b].operation[i],"ischecked",1);
} else{
this.$set( this.data[a].eventtype[b].operation[i],"ischecked",0);
this.checkOne=this.checkOne.map(res=>{
if( res!=this.data[a].eventtype[b].operation[i].actionid){return res;}
})
}
this.actionids.push(this.data[a].eventtype[b].operation[i].actionid);
}
this.api(this.data[a].eventtype[b].ischecked);
}else{//单选
var num1=0;
var num2=0;
var len=this.data[a].eventtype[b].operation.length;//单选框长度
this.data[a].eventtype[b].operation[c].ischecked=this.data[a].eventtype[b].operation[c].ischecked==1?0:1;
for(var i=0;i<len;i++){
if(this.data[a].eventtype[b].operation[i].ischecked==1){
num2++;//选中计数
}
else{
num1++;//没选计数
}
}
if(num1==len){
this.checkAll=this.checkAll.map(res=>{
if(res!=this.data[a].eventtype[b].eventtypeid){return res;}
});
this.data[a].eventtype[b].ischecked=0;
}
if(num2==len){
this.checkAll.push(this.data[a].eventtype[b].eventtypeid)
this.data[a].eventtype[b].ischecked=1;
this.$set(this.data[a].eventtype[b],"ischecked",1);
}
this.actionids=this.data[a].eventtype[b].operation[c].actionid;
this.api(this.data[a].eventtype[b].operation[c].ischecked)
}
api(ischecked){//权限选择接口
let para={
roleid:this.roleid,
ischecked:ischecked,
actionid:this.actionids.toString(),
}
addRolePower(para).then((res)=>{//取消权限
this.$notify({
message:res.msg,
type: 'success'
});
})
},
引用自夏天想
element-ui 里面el-checkbox多选框,实现全选单选的更多相关文章
- js做全选,用一个checkbox复选框做多个checkbox复选框的全选按钮,有一个复选框未被选择时,全选按钮的checked就为false
用一个checkbox复选框做多个checkbox复选框的全选按钮,有一个复选框未被选择时,全选按钮的checked就为false,当所有checkbox都被选中时,全选按钮也被选中. 详解: 有两种 ...
- Vue复选框的全选
<!DOCTYPE html><html> <head> <meta charset="utf-8"> ...
- js实现复选框的全选、全不选、反选
js中实现复选框的全选,全不选以及反选,分为两种情况: (1)选中“请选择”前面的复选框实现全选,不选中“请选择”前面的复选框实现全不选 <!DOCTYPE html PUBLIC " ...
- JQ实现复选框的全选反选不选
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【jQuery】复选框的全选、反选,推断哪些复选框被选中
本文与<[JavaScript]复选框的全选.反选.推断哪些复选框被选中>(点击打开链接)为姊妹篇,把里面内容再与jQuery框架中实现一次,相同做到例如以下的效果: 布局还是相同的布局, ...
- js实现复选框的全选、全不选和反选
js实现复选框的全选.全不选和反选 主要是用遍历的方法查找元素,然后通过改变checked的属性来选择,为true则是选中状态,为false则是未选状态 实现代码 <!DOCTYPE html& ...
- 【JavaScript】实现复选框的全选、全部不选、反选
以较为简洁的程序实现复选框的全选.全部不选.反选 操作. 并且将可变的部分设置为JS的参数,以实现代码复用. 全选和全不选 第一个参数为复选框名称,第二个参数为是全选还是全部不选. function ...
- 一天搞定jQuery(三)——使用jQuery完成复选框的全选和全不选
还记得之前我使用JavaScript来实现复选框的全选和全不选效果吗?如果读者初次翻阅本文,可记得看看教你一天玩转JavaScript(七)——使用JavaScript完成复选框的全选和全不选的效果! ...
- jQuery学习(五)——使用JQ完成复选框的全选和全不选
1.在系统后台进行人员管理时,进行批量删除,使用jq完成全选和全不选 步骤分析: 第一步:引入jquery文件 第二步:书写页面加载函数 第三步:为上面的复选框绑定单击事件 第四步:将下面所有的复选框 ...
- jQuery实现复选框的全选、反选、并且根据复选框的<checked属性>控制多个对应div的显示/隐藏
<!doctype html><html> <head> <meta charset="utf-8"> <title>j ...
随机推荐
- MySQL慢日志分析之pt-query-digest
http://www.php.cn/mysql-tutorials-357655.html 监控慢日志: pt-query-digest 切割分析慢日志 anemometer 删掉垃圾查询 pt-ki ...
- VS Project Property Manage
概念:Project Property 和 Property Sheet. Project Property:项目属性,是你当前项目的属性配制,保存在你工程的配制文件中,rojectName.vcxp ...
- 阶段1 语言基础+高级_1-3-Java语言高级_07-网络编程_第2节 TCP协议_4_TCP通信的服务器端代码实现
表示服务器的类是ServerSocket 启动服务器端 再启动客户端 客户端代码修改获取服务端会写的数据 先启动服务器端,再启动客户端 客户端打印: 服务器端读取:
- Python笔记(二十九)_模块
模块 在Python中,一个.py文件就是一个模块 if __name__ == '__main__':所有模块都有一个 __name__ 属性,__name__ 的值取决于如何应用模块 run当前文 ...
- 【opencv】opencv图像识别的一些基础的基础函数的使用方法
import cv2 import numpy as np from matplotlib import pyplot as plt pic_path = "deal_with.png&qu ...
- jdbc步骤:
一.注册数据库驱动 Class.forName("com.mysql.jdbc.Driver"); 二.建立连接(Connection) Connection conn = Dri ...
- git.ZC_命令积累
1.删除文件 git rm 想要删除的文件的名字及其后缀 git commit -m "对本次提交的描述信息" git push 删除文件夹,执行命令: git rm 想要删除的文 ...
- Mac--PHP已经开启gd扩展验证码不显示
错误显示:Call to undefined function imagettftext() 原因: mac系统中自带的php的gd库中,缺少对freetype的支持,导致图片无法显示. 解决: 1 ...
- Java -Tips
1. /* xxxx */表示多行注释,双斜杠开始表示单行注释.多行注释的快捷键: 先选中多行代码,然后按下ctrl+/就可以把选中的多行代码给注释掉.
- Oracle数据库用户介绍
Oracle数据库创建的时候,创建了一系列默认的用户,有时候可能我们不小心忘记创建了某个用户,比如SCOTT用户,我们就需要使用Oracle提供的脚本来创建,介绍如下: 1.SYS/change_on ...