简体   繁体   English

为什么当我尝试更新任何节点时 Visjs 网络重新出现

[英]why Visjs network is reappearing when i try to update any node

I am trying to update the hidden attribute of visjs network's node.我正在尝试更新 visjs 网络节点的隐藏属性。 by clicking the node, the node should be invisible without disturbing the graph.通过单击节点,该节点应该是不可见的,而不会干扰图形。 can anyone help me with this I am new.谁能帮我这个我是新来的。 code I am trying -我正在尝试的代码 -

this.network.on('click', function (properties) {
      var ids = properties.nodes;
      if(ids.length==0)
        return
   
      treeData.nodes.update({id:ids,hidden:true}) //treeData is object containing two dataSets (nodes and edges);
      
    });

The object generated by the click event contains an array of IDs rather than a single ID.单击事件生成的对象包含一组 ID 而不是单个 ID。 The definition of this can be seen at https://visjs.github.io/vis-network/docs/network/#Events .这个定义可以在https://visjs.github.io/vis-network/docs/network/#Events看到。

At present the code is passing this array in as a single id treeData.nodes.update({id:ids,hidden:true}) which generates an error "Error: Node must have an id" .目前,代码将此数组作为单个 id treeData.nodes.update({id:ids,hidden:true}) ,这会生成错误"Error: Node must have an id" Instead of this it should loop through the array of IDs updating each.相反,它应该遍历更新每个 ID 的数组。

network.on('click', function (properties) {
  var ids = properties.nodes;

  // ids is an array, update each item
  for (let i = 0; i < ids.length; i++){
    treeData.nodes.update({id:ids[i],hidden:true})
    }      
});

Example can be found at https://jsfiddle.net/3yshgam1/ and also incorporated into this post below.示例可以在https://jsfiddle.net/3yshgam1/上找到,也包含在下面的这篇文章中。

 // create an array with nodes var nodes = new vis.DataSet([ { id: 1, label: "Node 1" }, { id: 2, label: "Node 2" }, { id: 3, label: "Node 3" }, { id: 4, label: "Node 4" }, { id: 5, label: "Node 5" }, ]); // create an array with edges var edges = new vis.DataSet([ { from: 1, to: 3 }, { from: 1, to: 2 }, { from: 2, to: 4 }, { from: 2, to: 5 }, { from: 3, to: 3 }, ]); // create a network var container = document.getElementById("mynetwork"); var treeData = { nodes: nodes, edges: edges, }; var options = {}; var network = new vis.Network(container, treeData, options); network.on('click', function (properties) { var ids = properties.nodes; // ids is an array, loop through the items for (let i = 0; i < ids.length; i++){ treeData.nodes.update({id:ids[i],hidden:true}) } });
 #mynetwork { width: 600px; height: 180px; border: 1px solid lightgray; }
 <script src="https://visjs.github.io/vis-network/standalone/umd/vis-network.min.js"></script> <div id="mynetwork"></div>

Full example:完整示例:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 边缘从节点到另一个边缘visjs Angular 4 - Edge from node to another edge visjs Angular 4 Visjs 使用画布外的按钮动态添加节点 - Visjs Add node dynamically with button outside canvas 当我尝试更新FireStore集合中的数据时收到错误 - Receive error when i try to update data in my fireStore collection 尝试安装@ schematics / update @ 0.803.2时出错 - Error when I try install @schematics/update@0.803.2 为什么在尝试声明局部变量时会出错? - Why I get error when I try to declare local variable? 在VisJs中创建网络图时,选项对象出错(角度4) - Error in options object during creating Network graph in VisJs (Angular 4) 为什么在尝试通过id获取元素时会得到null? - Why I get null when try get element by id? 知道为什么我的 GitHub 应用程序设法在本地使用相同的服务调用来更新文件内容并且在部署时失败吗? - Any idea why my GitHub App manages to update the file content using the same service call on local and fails when I deploy it? 当我尝试更新为angular2版本候选者时遇到一些困难 - I have some difficulties when I try to update to angular2 release candidate 每当我尝试安装任何东西时,我总是会遇到这些类型的错误 - i always get these type of errors when ever i try to install any thing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM