el-table 子级选中父级勾选 子级无一选中父级取消勾选

发布时间 2023-08-07 11:45:57作者: 菜彩
 // 选中子级父级也选中
            if(row.parentId!=0){
                    let parent = this.archiveTypeList.find((x=>x.id===row.parentId));
                    this.$refs.multipleTable.toggleRowSelection(parent,true);
                    let childrenLen=0;
                    parent.children.forEach((i)=>{
                        let selected = selection.length && selection.indexOf(i) !== -1
                        if(selected === true){
                            //当前行被选中  
                            childrenLen++
                        }
                    })
                 // 子级所有取消选中 父级也取消选中
                    if(childrenLen==0){
                        this.$refs.multipleTable.toggleRowSelection(parent,false);
                    }
             }