如何在 cytoscape 中实现该功能.js通过单击节点在两个节点之间添加边缘?



当用户先单击一个节点,然后单击第二个节点时,我想连接两个节点。

尝试使用 cy.bind(( 函数。您可以在节点上绑定 click 事件,并将该节点的 id 保存在数组中,例如:

cy.unbind('click');          // unbind event to prevent the event to fire 
cy.bind('click ', 'node', function (evt) { 
// add the node to an array (node is in evt.target())
// if there are 2 nodes in the array, remove them after creating an edge between them
cy.add(//your new edge);
array.splice(0, 2);   // remove the first 2 elements of your array
});

给未来的提示:请考虑阅读stackoverflow的How-to-ask部分,提出问题而不是提供实现目标的尝试不是stackoverflow的要点:)

下次,向我们展示您到目前为止所得到的内容,即使它完全错误或未完成,那么您也不会被其他用户投票否决;)

最新更新