|
|
@@ -204,10 +204,33 @@
|
|
|
},
|
|
|
|
|
|
confirm(id, name) {
|
|
|
+
|
|
|
+ // console.log(this.getParentNodeId(this.classificationList, id))
|
|
|
|
|
|
this.categoryLevelId = id
|
|
|
this.getList()
|
|
|
},
|
|
|
+
|
|
|
+ getParentNodeId(tree, childId) {
|
|
|
+ // 遍历树节点
|
|
|
+ for (let node of tree) {
|
|
|
+ // 如果当前节点就是目标节点的父节点,直接返回当前节点id
|
|
|
+ if (node.children && node.children.some(child => child.id === childId)) {
|
|
|
+ return node.id;
|
|
|
+ }
|
|
|
+ // 否则继续遍历当前节点的子节点
|
|
|
+ if (node.children) {
|
|
|
+ const parentId = getParentNodeId(node.children, childId);
|
|
|
+ if (parentId !== null) {
|
|
|
+ return parentId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果没有找到父节点,则返回null
|
|
|
+ return null;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
|
|
|
getList() {
|
|
|
let param = {
|