在用iview的時候發現iview的樹中獲取半選和全選的函數getCheckedAndIndeterminateNodes在我使用的iview版本里面是沒有提供的,
於是自己寫了一下獲取全選和半選節點的數據
這個是最最笨的方法
this.halfCheckData = [] checkData = this.$refs.menuTree.getCheckedNodes() this.getHalfCheckData(checkData) let allCheckData = Array.from(new Set(checkData.concat(this.halfCheckData))) console.error('allCheckData', allCheckData.map((item) => item.name)) getHalfCheckData (checkData) { if (!checkData) { return } let halfData = [] this.halfTag = false let checkfidData = checkData.map((item) => { return item.fid }) checkfidData = Array.from(new Set(checkfidData)) checkfidData.forEach((item) => { if (item) { this.halfCheckNode = {} this.findParent(item, this.menuTreeData) halfData.push(this.halfCheckNode) } }) if (halfData && halfData.length > 0) { this.getHalfCheckData(halfData) } }, findParent (id, tree) { if (this.halfTag) { return } for (let item of tree) { if (item.id === id) { this.halfCheckNode = item this.halfCheckData.push(item) return } if (item.children && item.children.length > 0) { this.findParent(id, item.children) } } }
