| | |
| | | if (checked) { |
| | | this.addAllChildren(row.children); |
| | | this.addToParentList(row); |
| | | // 勾选行时,将当前行以及其所有子节点添加到ParentList中 |
| | | // 勾选行时将所有节点添加到ParentList中 |
| | | } else { |
| | | this.removeAllChildren(row.children); |
| | | this.removeFromParentList(row); |
| | | // 取消勾选行时,将当前行以及其所有子节点从ParentList中移除 |
| | | // 取消勾选将所有节点添加从ParentList中移除 |
| | | } |
| | | |
| | | // console.table(this.ParentList); |
| | | }, |
| | | //子节点添加 |
| | | addAllChildren(children) { |
| | | for (let child of children) { |
| | | this.addToParentList(child); |
| | | // 将子节点添加到 ParentList 中 |
| | | if (child.children && child.children.length > 0) { |
| | | this.addAllChildren(child.children); |
| | | // 递归调用继续添加子节点的子节点 |
| | | } |
| | | } |
| | | }, |
| | | //子节点移除 |
| | | removeAllChildren(children) { |
| | | for (let child of children) { |
| | | this.removeFromParentList(child); |
| | | // 将子节点从 ParentList 中移除 |
| | | if (child.children && child.children.length > 0) { |
| | | this.removeAllChildren(child.children); |
| | | // 递归调用继续移除子节点的子节点 |
| | | } |
| | | } |
| | | }, |
| | | //当前父节点添加 |
| | | addToParentList(item) { |
| | | const classifyOid = item.attributes.classifyOid; |
| | | if (!this.isClassifyOidExists(classifyOid)) { |
| | |
| | | classifyOid: classifyOid, |
| | | }; |
| | | this.ParentList.push(record); |
| | | // 将节点添加到ParentList中 |
| | | } |
| | | }, |
| | | //当前父节点移除 |
| | | removeFromParentList(item) { |
| | | const classifyOid = item.attributes.classifyOid; |
| | | if (this.isClassifyOidExists(classifyOid)) { |
| | |
| | | if (index !== -1) { |
| | | this.ParentList.splice(index, 1); |
| | | } |
| | | // 将节点从ParentList中移除 |
| | | } |
| | | }, |
| | | //判重-ParentList |
| | | isClassifyOidExists(classifyOid) { |
| | | return this.ParentList.some(item => item.classifyOid === classifyOid); |
| | | }, |
| | | //查找index位置 |
| | | findIndexByClassifyOid(classifyOid) { |
| | | return this.ParentList.findIndex(item => item.classifyOid === classifyOid); |
| | | }, |