递归查找树中的某个节点

nodes是树结构数据,id是要查找的树节点的id

const node = this.getNode(nodes, this.id);
console.log(node);


getNode(treeNodes: Array<any>, key) {
    let node;
    for (const treeNode of treeNodes) {
      if (treeNode.Id === key) {
        node = treeNode;
        break;
      }
      if (!Util.IsNullOrEmpty(treeNode.Children)) {
        node = this.getNode(treeNode.Children, key);
        if (node) {
          break;
        }
      }
    }
    return node;
  }

 

上一篇:云原生爱好者周刊:K8s Security SIG 发布 Kubernetes 策略管理白皮书


下一篇:Kubernetes监控-Prometheus