Is there a way of getting the cystoscape object associated with a DOM element?

烈酒焚心 提交于 2020-01-16 16:13:08

问题


I currently do the following:

let $cy = $('#cy');
let cy = cytoscape({
   container: $cy,
   ...
});

$cy.data('cytoscape', cy);

The above allow me to reobtain the cytoscape object (e.g. in a event handler) as follows:

let cy = $cy.data('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)?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/52602724/is-there-a-way-of-getting-the-cystoscape-object-associated-with-a-dom-element

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