cytoscape.js - cy.on('select') callback only once -
i have createtable function receives collection of nodes (or array of nodes), able draw table.
i switching cytoscape.js now, , don't know how have listener select event properly.
doing this:
cy.on('select', 'node', function(event){ window["selectednodes"] = cy.$('node:selected'); });
i have information need draw table, cannot call createtable function inside because call function several times (once per node selected). i've tried use cy.on , cy.once, without success.
here question:
how can have listener selection event, selected nodes , call (only once) createtable function ?
i can obtain selected node using this:
cy.elements('node:selected', console.log("my callback function"));
but outside event listener (select / click) doesn't work need.
please, appreciated.
thank you.
debounce callback if multiple events come in 1 after another, batched:
var timeout; cy.on('select', 'node', function(event){ cleartimeout( timeout ); timeout = settimeout(function(){ window["selectednodes"] = cy.$('node:selected'); // , on... }, 100); // may have adjust val });
Comments
Post a Comment