小编Sur*_*hil的帖子

如何有效过滤保留现有结构的树视图?

我有一个树结构的JSON应该被过滤,结果应该保留树结构.

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"
  }
];
Run Code Online (Sandbox Code Playgroud)

示例:

1)如果搜索查询是父1

预期结果 :

[
  {
    text: "Parent 1",
    nodes: [
      {
        text: "Child 1",
        type: "Child",
        nodes: [
          {
            text: …
Run Code Online (Sandbox Code Playgroud)

javascript treeview optimization tree angularjs

0
推荐指数
1
解决办法
1639
查看次数

标签 统计

angularjs ×1

javascript ×1

optimization ×1

tree ×1

treeview ×1