twitter-bootstrap 以编程方式刷新 Bootstrap Treeview

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36353641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 23:49:02  来源:igfitidea点击:

Refresh Bootstrap Treeview programmatically

javascriptarraystwitter-bootstraptwitter-bootstrap-3treeview

提问by tarzanbappa

I have a Bootstrap tree view which binds to a json array..

我有一个绑定到 json 数组的 Bootstrap 树视图。

 $('#tree').treeview({data: data,
           onNodeSelected: function(event, data) {

            $m.nodeSelected(event,data);
          }});

And the array that binded to the treeview is..

绑定到树视图的数组是..

var data = [
    {
      "text": "Parent1",
      "selectable": "false",
      "nodeType": "main",
      "nodes": [
        {
          "text": "Child1",
          "typeId": "aa2d4ea9-bfad-4a5b-8794-994e7e482808",
          "nodeType": "sub"
        },
        {
          "text": "Child2",
          "typeId": "e01bd0cb-c93b-40f9-be44-be67f20668aa",
          "nodeType": "sub"
        }
      ]
    },
    {
      "text": "Parent2",
      "selectable": "false",
      "nodeType": "main",
      "nodes": [
        {
          "text": "Child1",
          "typeId": "a0256aa3-b2ef-53d7-1270-a5029e7138ce",
          "nodeType": "sub"
        }
      ]
    }
  ]

Here is what I need..

这是我需要的..

I need to add a new child node / remove a existing child node from the treeview datasource and refresh it.

我需要添加一个新的子节点/从树视图数据源中删除一个现有的子节点并刷新它。

I've tried but unable to find a solution.

我已经尝试过但无法找到解决方案。

回答by warch

Just call:

只需致电:

$('#tree').treeview({data: data,
     onNodeSelected: function(event, data) {
        $m.nodeSelected(event,data);
     }
});

again when you have changed the datavariable:

再次更改data变量后:

example: https://jsfiddle.net/k8m911u9/1/

示例:https: //jsfiddle.net/k8m911u9/1/

回答by miralong

Thi is possible in development version: https://github.com/jonmiles/bootstrap-treeview/tree/developthere is added metods for add, delete, update node

这在开发版本中是可能的:https: //github.com/jonmiles/bootstrap-treeview/tree/develop有添加、删除、更新节点的方法