我有节点和边缘的网络图,并希望在点击后获取节点数据.我现在有
- var network = new vis.Network(container,data,options);
- network.on( 'click',function(properties) {
- console.log('clicked node ' + properties.nodes);
- });
但这只是给了我一些内部身份[105].有没有办法获取与节点关联的实际数据.
解决方法
您在属性中获得的节点ID不是“某个内部ID”,但这些是您自己定义的节点的ID.您可以使用以下节点从您自己的DataSet中读取节点的数据:
- var nodes = new vis.DataSet([...]);
- var edges = new vis.DataSet([...]);
- var data = {nodes: nodes,edges: edges};
- var network = new vis.Network(container,function(properties) {
- var ids = properties.nodes;
- var clickedNodes = nodes.get(ids);
- console.log('clicked nodes:',clickedNodes);
- });