有没有一种方法可以获取与DOM元素关联的cystoscape对象? [英] Is there a way of getting the cystoscape object associated with a DOM element?
问题描述
我目前正在执行以下操作:
I currently do the following:
let $cy = $('#cy');
let cy = cytoscape({
container: $cy,
...
});
$cy.data('cytoscape', cy);
以上内容使我可以重新获取cytoscape对象(例如在事件处理程序中),如下所示:
The above allow me to reobtain the cytoscape object (e.g. in a event handler) as follows:
let cy = $cy.data('cytoscape');
是否有内置的方法来获取cytoscape对象,因此我可以避免做所有这些工作(从技术上讲
Is there a builtin method of obtaining the cytoscape object so I can avoid doing all this work (and technically mess with a element own by the library)?
推荐答案
通常假定您将Cytoscape实例保留在一个共享变量中。代码,因此您无需从DOM对象获取它。
It is generally assumed that you will keep Cytoscape instance in a shared variable in the code, so you won't need to get it from the DOM object.
您可以像以下这样获取与DOM元素关联的Cytoscape实例:
You can get the Cytoscape instance associated with a DOM element like this:
document.getElementById('cy')._cyreg.cy
请注意,据我所知,这没有记录。
Be aware, as far as I know this is not documented.
这篇关于有没有一种方法可以获取与DOM元素关联的cystoscape对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!