我整天都在为此苦苦挣扎。将磁铁设置为无源对我来说不是一个足够好的解决方案。在挖掘源代码后,我最终得到的是使用纸对象的 validateMagnet 函数。我从磁铁获取端口,然后从源模型获取所有出站链接。如果任何链接使用相同的点,我会拒绝验证。这是代码:
validateMagnet: function(cellView, magnet) {
// Prevent links from ports that already have a link
var port = magnet.getAttribute('port');
var links = graph.getConnectedLinks(cellView.model, { outbound: true });
var portLinks = _.filter(links, function(o) {
return o.get('source').port == port;
});
if(portLinks.length > 0) return false;
// Note that this is the default behaviour. Just showing it here for reference.
// Disable linking interaction for magnets marked as passive (see below `.inPorts circle`).
return magnet.getAttribute('magnet') !== 'passive';
},