递归实现 树结构数据回显

treeShow() {
      let oneLists = this.formItem.org_one.split(",");
      let twoLists = this.formItem.org_two.split(",");
      let threeLists = this.formItem.org_three.split(",");
      let selectedLists = oneLists.concat(twoLists, threeLists);
      let selectedNamesLists = [];

      console.log(this.branchDatas)
      this.selectedTreeList = this.branchDatas
      console.log(this.selectedTreeList)

      this.selectedTreeList.forEach(a => {
        this.hx(a, selectedLists, selectedNamesLists)
      })

      this.selectedNames = selectedNamesLists.join(",");
    },
    hx(a, selectedLists, selectedNamesLists) {
      let index = selectedLists.findIndex(item => item == a.organ_id)
      if (index != -1) {
        a.checked = true;
        selectedNamesLists.push(a.depart_fullname);
      } else {
        a.checked = false
      }

      if (a.children && a.children.length) {
        a.children.forEach(b => {
          this.hx(b, selectedLists, selectedNamesLists)
        })
      }
    },

你可能感兴趣的:(iview,tree)