在用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) } } }