Accessing node data in vis.js click handler

后端 未结 1 1177
既然无缘
既然无缘 2021-02-13 06:33

I have a network graph of nodes and edges and would like to get the node data once it gets clicked. e.g,

var network = new vis.Network(container, data, options);
         


        
相关标签:
1条回答
  • 2021-02-13 07:08

    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);
    });
    
    0 讨论(0)
提交回复
热议问题