gpt4 book ai didi

javascript - 删除网络 vis.js 中的边缘

转载 作者:行者123 更新时间:2023-12-02 03:15:26 24 4
gpt4 key购买 nike

在 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>

最佳答案

现在没问题了!

我可以用“id”作为边缘来做到这一点:

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

function test1(){
data.edges.remove([1]);
}

关于javascript - 删除网络 vis.js 中的边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56317324/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com