/* 移入tree */ moveTree(){ if(this.selectGroups.length>0){ this.selectGroups.forEach(item=>{ this.parentNodes.find(val=>{ if(val.id == item.pid){ /* 添加节点 */ let node = this.treeObj.getNodeByParam("id", val.id, null); this.treeObj.addNodes(node,item) /* 取消新增节点的选中状态 */ let cancelNode = this.treeObj.getNodeByParam("id", item.id, null); this.treeObj.checkNode(cancelNode,false,true); } }) this.tableData.splice(this.tableData.findIndex(val => val.id === item.id), 1) }) }else{ this.$message.warning('请选择要移动的数据') } },
树移到表格
/* 移入表格 */ moveTable(){ let arr=[] let nodes = this.treeObj.getCheckedNodes(true); if(nodes.length>0){ nodes.forEach(item=>{ this.tableData.find(val=>{ arr.push(val.id) }) if(arr.indexOf(item.id)>-1) return this.$message.error("数据重复,请勿重新添加") this.treeObj.removeNode(item) this.tableData.push(this.filterObj(item,["checked","codeSetId",'id','img','infoItemFlag','isMult','itemType','locked','mult','orgCode','pid','sort','syrs','text'])) // 调用下面的方法,去除多余字段 }) }else{ this.$message.warning('请勾选数据') } },
封装的过滤字段
/* 过滤对象多余字段 */ filterObj(obj, arr) { const result = {} Object.keys(obj).filter((key) => arr.includes(key)).forEach((key) => { result[key] = obj[key] }) return result }