Vis.js: how to access the network inside an event handler?

我的梦境 提交于 2019-12-25 11:09:07

问题


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.

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

network.on("dragEnd",saveToTiddlerAfterDragging);

However what's passed to the handler is this object:

{
  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}
  }
}

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.


回答1:


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.



来源:https://stackoverflow.com/questions/46101929/vis-js-how-to-access-the-network-inside-an-event-handler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!