我使用了以下链接中的解决方案来防止我的节点捕获 mousedown 事件,因此用户可以通过在屏幕的任何位置(包括节点)拖动来平移视图。
How to totally disable elements events?
但是,当我在我的应用中选择选择工具时,我无法让 events
恢复正常。我将 events
设置为“是”,但节点和边仍然拒绝被选中。如果我删除 node.style('events', 'no');
,元素将在选择模式下可选择,但它们也会触发 mousedown,因此会在平移视图时造成一些麻烦。
此代码在启动平移模式(启动时的默认模式)时首先运行:
this.cy.autoungrabify(true);
this.cy.autounselectify(true);
this.cy.userPanningEnabled(true);
this.cy.$('node, edge').forEach(node => {
node.style('events', 'no');//this works perfectly preventing elements from firing events
});
那么如果我选择选择模式(反之亦然):
this.cy.autoungrabify(false);
this.cy.autounselectify(false);
this.cy.userPanningEnabled(false);
this.cy.$('node, edge').forEach(node => {
node.style('events', 'yes'); //but this takes no effect, elements remain unselectable.
//property is actually set to 'yes', I checked it
});
... setting some event listeners on nodes and edges ...
如何将 events
恢复正常?