Vis.js:如何在事件处理程序中访问网络? [英] Vis.js: how to access the network inside an event handler?

查看:110
本文介绍了Vis.js:如何在事件处理程序中访问网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用vis.js来显示和编辑图形(因此存储了它的节点,边和选项).为了实现这一点,我需要保存网络(=图形)在各种事件上的更改.其中的一个是通过拖放来重新排列.

I'd like to use vis.js for displaying and editing a graph (hence storing its nodes, edges and options). To implement this, I need to save changes of the network (=graph) on various events. On of them is rearranging via drag and drop.

现在,有一个on方法支持dragEnd事件,这意味着我可以做类似的事情

Now, there's an on method which supports the dragEnd event meaning I can do stuff like

network.on("dragEnd",saveToTiddlerAfterDragging);

传递给处理程序的内容是该对象:

{
  nodes: [Array of selected nodeIds],
  edges: [Array of selected edgeIds],
  event: [Object] original _ event,
  pointer: {
    DOM: {x:pointer_x, y:pointer_y},
    canvas: {x:canvas_x, y:canvas_y}
  }
}

似乎没有对network本身的引用.那么如何访问呢?我想在network本身之外的其他范围内定义saveToTiddlerAfterDragging.

Seems like there's no reference of the network itself. So how to access it? I'd like to define saveToTiddlerAfterDragging in another scope than network itself.

推荐答案

好吧,在阅读文档和编写问题时,我猜测在事件处理程序上下文中network实际上是this.不确定对于所有事件处理程序是否都是正确的,但可以与dragEnd一起使用.

Ok, while reading docs and writing the question, I wild-guessed that the network is actually this in the event handler context. Not sure if it's true for all the event handlers but works with the dragEnd one.

这篇关于Vis.js:如何在事件处理程序中访问网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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