访问vis.js单击处理程序中的节点数据 [英] Accessing node data in vis.js click handler

查看:610
本文介绍了访问vis.js单击处理程序中的节点数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有节点和边缘的网络图,并希望在点击后获取节点数据。我目前有

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);
});

但这只是给了我一些内部ID [105]。有没有办法获取与节点关联的实际数据。

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

推荐答案

您在属性中获得的节点ID不是某个内部ID,但这些是节点的ID你自己定义的。您可以使用以下节点从您自己的 DataSet 中读取节点的数据:

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);
});

这篇关于访问vis.js单击处理程序中的节点数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆