el-tree選中子級時默認選中父級(角色授權)


問題1:選中子級時默認選中父級

  <el-tree :data="menuData"
                        show-checkbox
                        default-expand-all
                        node-key="id"
                        :props="defaultProps"
                        ref="menuTree"
                        :render-content="renderContent"
                        :expand-on-click-node="false">
               </el-tree>
//提交
    submitRole(){
 // 點擊子級時默認也選中父級Id傳給后台concat合並
//
this.$refs.menuTree.getCheckedKeys()獲取子級id
//this.$refs.menuTree.getHalfCheckedKeys()獲取父級id
var checkKeys = this.$refs.menuTree.getCheckedKeys().concat(this.$refs.menuTree.getHalfCheckedKeys()); 
let newArr = checkKeys.map(item => { return { menuId
: item, roleId: this.roleId } });
let lists=
{ lists:newArr }
roleImpower(lists).then(res=>{
if(res.code ==200){ this.$message.success("授權成功"); }
else{ this.$message.error("授權失敗"); } })
console.log(newArr)
this.roleDia = false
},

 

問題2:回顯有父級id,默認選中父級下所有子級

 

    // 組授權
            handleAuth(id){
//獲取回顯的id
getRoleId(id).then(res=>{    let that = this if (res.data.lists) {    setTimeout(function () { res.data.lists.forEach((value)=>{ that.$refs.menuTree.setChecked(value,true,false) })   },200);
              //用下面方法,回顯帶有父級id,會默認選中所有子級, // var aaa = this.$refs.menuTree.setCheckedKeys(res.data.lists) } }) this.roleId = id //回顯權限列表 allMenu(this.listQuery).then(res =>
{ this.loading = false this.menuData = res.data.menu || [] }, error => { this.loading = false this.$message.error(error.message) }) this.roleDia = true },


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM