Accessing node data in vis.js click handler

ぃ、小莉子 提交于 2020-01-22 14:00:19

问题


I am having a network graph of nodes and edges and would like to get the node data once it gets clicked. I currently have

var network = new vis.Network(container, data, options);
network.on( 'click', function(properties) {
    console.log('clicked node ' + properties.nodes);
});

But this just gives me some internal id [105]. Is there a way to get the actual data that is associated with the node.


回答1:


The node ids that you get in the properties is not "some internal id", but these are the id's of the nodes that you defined yourself. You can simply read the node's data from your own DataSet with nodes like:

var nodes = new vis.DataSet([...]);
var edges = new vis.DataSet([...]);
var data = {nodes: nodes, edges: edges};

var network = new vis.Network(container, data, options);
network.on( 'click', function(properties) {
    var ids = properties.nodes;
    var clickedNodes = nodes.get(ids);
    console.log('clicked nodes:', clickedNodes);
});


来源:https://stackoverflow.com/questions/35906493/accessing-node-data-in-vis-js-click-handler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!