问题
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