MCPcopy Create free account
hub / github.com/MankaiHuang/screen-visualization / getNodePath

Function getNodePath

public/iframe/lib/js/commonFun.js:100–118  ·  view source on GitHub ↗
(node, key, value)

Source from the content-addressed store, hash-verified

98 }
99 },
100 getNodePath(node, key, value) {
101 // 这里可以自定义push的内容,而不是整个node,而且这里node也包含了children
102 this.nodePathArray.push(node.property.elementId);
103 // 找到符合条件的节点,通过throw终止掉递归
104 if (node.property[key] === value) {
105 // 也可以直接使用return;结束循环
106 throw ("over!");
107 }
108 if (node.property.children && node.property.children.length > 0) {
109 for (let i = 0; i < node.property.children.length; i++) {
110 this.getNodePath(node.property.children[i], key, value);
111 }
112 // 当前节点的子节点遍历完依旧没找到,则删除路径中的该节点
113 this.nodePathArray.pop();
114 } else {
115 // 找到叶子节点时,删除路径当中的该叶子节点
116 this.nodePathArray.pop();
117 }
118 },
119 findTemplateForId(id, templateList = this.templateList) {
120 // 因为存在children的情况 因此这里要遍历所有元素去查找
121 const nowTemplate = []

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected