element - ui default - checked - keys 는 노드 아래 의 모든 하위 노드 를 해결 방법 으로 선택 합 니 다.

6182 단어 ui자바 script
<el-tree
            class="filter-tree"
            :data="permissionData"
            :props="props"
            node-key="id"
            ref="treeForm"
            show-checkbox
            :default-checked-keys="this.savedPermissionIds"
            :default-expanded-keys="this.savedPermissionIds"
            @check="getCheckedNodes"
          >el-tree>
   showDialog(id) {
      this.isShowPermissionTree = true;
      this.roleId = id;
      this.savedPermissionIds = [];
      this.getPermissionTree();
    },
    //         id      
    getCheckedNodes() {
      // let selectedPermission = this.$refs.treeForm.getCheckedNodes(false, true); //(leafOnly, includeHalfChecked)      boolean      ,1.         ,     false 2.         ,     false
      // this.permissionIds = selectedPermission.map(item => {
      //   return item.id;
      // });
      let parentArr = this.$refs.treeForm.getHalfCheckedKeys();
      let childeArr = this.$refs.treeForm.getCheckedKeys();
      let arr = childeArr.concat(parentArr);
      this.permissionIds = arr;
    },
    //  
    cancel() {
      this.isShowPermissionTree = false;
      this.savedPermissionIds = [];
      this.getPermissionTree();
    },
    //        
    getPermissionTree() {
      menulistByPid({ flag: 1 }).then(res => {
        this.permissionData = res.body;
        //        id   
        getPermissionIds({ roleId: this.roleId }).then(res => {
          this.savedPermissionIds = res.body;
          let newArr = [];
          let item = "";
          if (this.savedPermissionIds && this.savedPermissionIds.length !== 0) {
            this.savedPermissionIds.forEach(item => {
              this.checked(item, this.permissionData, newArr);
            });
            this.savedPermissionIds = newArr;
            // console.log("this.savedPermissionIds111", this.savedPermissionIds);
          }
        });
      });
    },
    checked(id, data, newArr) {
      data.forEach(item => {
        if (item.id == id) {
          if (item.items && item.items.length == 0) {
            newArr.push(item.id);
          }
        } else {
          if (item.items != null && item.items.length != 0) {
            this.checked(id, item.items, newArr);
          }
        }
      });
      // console.log("newArr", newArr);
    },

 
다음으로 전송:https://www.cnblogs.com/Byme/p/11551504.html

좋은 웹페이지 즐겨찾기