问题描述
我想使用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:如何在事件处理程序中访问网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!