删除网络vis.js中的优势

时间:2019-05-26 20:58:49

标签: vis.js

在vis.js中,我可以轻松添加边缘(功能测试),但不能删除现有边缘(功能测试1)。为什么?

不幸的是,我现在无法访问文档:visjs.org的“此处没有GitHub Pages站点”。谢谢!

<input onclick=test() type="button" value="add edge 1 to 4 : ok">
<input onclick=test1() type="button" value="remove edge 1 to 2: not ok">

<div id="mynetwork"></div>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.js"></script>

<script type="text/javascript">

    function test(){
        data.edges.add([{from: 1, to: 4}]);
    }

    function test1(){
        data.edges.remove([{from: 1, to: 2}]);
    }

    // GENERAL TEST
    var nodes = [
    {id: 1, label: 'Node 1'},
    {id: 2, label: 'Node 2'},
    {id: 3, label: 'Node 3'},
    {id: 4, label: 'Node 4'}
    ];

    var edges = [
    {from: 1, to: 2},
    {from: 1, to: 3},
    {from: 2, to: 4}
    ];

    nodesd = new vis.DataSet(nodes);
    edgesd = new vis.DataSet(edges);
    var container = document.getElementById('mynetwork');
    var data = {
        nodes: nodesd,
        edges: edgesd
    };

    var options = {
        nodes: {
            size:15
        },
        edges: {
            color: {
                inherit: "both"
            }
        }
    };
    network = new vis.Network(container, data, options);
</script>

1 个答案:

答案 0 :(得分:0)

现在可以了!

我可以使用“ id”作为边缘:

<!DOCTYPE html>
<html>

  <head>
    <title>Example-1</title>
    <link rel="stylesheet" href="Example.css" type="text/css">
  </head>

  <body>
    <div class="img-box">
      <div class="text">
      </div>
    </div>
  </body>

</html>