如何从树视图中过滤保留其现有结构?

时间:2021-02-18 10:12:05

标签: javascript

我的树结构与下面相同

var tree = [
  {
    text: "Parent 1",
    nodes: [
      {
        text: "Child 1",
        type: "Child",
        nodes: [
          {
            text: "Grandchild 1"
            type: "Grandchild"
          },
          {
            text: "Grandchild 2"
            type: "Grandchild"
          }
        ]
      },
      {
        text: "Child 2",
        type: "Child"
      }
    ]
  },
  {
    text: "Parent 2",
    type: "Parent"
  },
  {
    text: "Parent 3",
    type: "Parent"
  }
];

How to effectively filter tree view retaining its existing structure?

唯一的区别是在example1中,如果我们搜索parent 1,它将返回空节点[],因为没有一个子节点包含文本“Parent 1”

0 个答案:

没有答案
相关问题