Javascript 在链接上指定类似于源/目标的单元格时发生的事件?
我使用默认链接,并且我希望从链接中限制源和目标,因为我只需要rectsource和circletarget之间的链接 我已经用link.onchange:source和link.onchange:target尝试过了,但是这个事件不会在我想要的时候启动 有人知道这个问题的解决办法吗Javascript 在链接上指定类似于源/目标的单元格时发生的事件?,javascript,jointjs,Javascript,Jointjs,我使用默认链接,并且我希望从链接中限制源和目标,因为我只需要rectsource和circletarget之间的链接 我已经用link.onchange:source和link.onchange:target尝试过了,但是这个事件不会在我想要的时候启动 有人知道这个问题的解决办法吗 var defaultLinks = new joint.dia.Link({ attrs: { '.marker-source': {transfo
var defaultLinks = new joint.dia.Link({
attrs: {
'.marker-source': {transform: 'scale(0.001)' },
'.marker-target': {fill:'black', d: 'M 10 0 L 0 5 L 10 10 z' },
'.connection-wrap': {
stroke: 'black'
}
},
smooth:true,
path: []
});
defaultLinks.on('change:source',function(){
alert("change source")
});
defaultLinks.on('change:target',function(){
alert("change source")
});
this.paper = new joint.dia.Paper({
el: this.paperScroller.el,
width: 1200,
height: 1000,
gridSize: 10,
perpendicularLinks: true,
model: this.graph,
defaultLink: defaultLinks
});
您可以在纸张选项中使用ValidateConnectionCellView、magnetS、cellViewT、magnetT、end、linkView功能。本教程显示了以下用法:。在您的情况下,您将使用类似“未测试”的内容:
var paper = new joint.dia.Paper({
validateConnection: function(cellViewS, magnetS, cellViewT, magnetT, end, linkView) {
// Only rectangle can be the source, if it is not, we do not allow such connection:
if (cellViewS.model.get('type') !== 'basic.Rect') return false;
// Only circle can be the target, if it is not, we do not allow such a connection:
if (cellViewT.model.get('type') !== 'basic.Circle') return false;
// Connection is allowed otherwise.
return true;
},
...
})
您可以在纸张选项中使用ValidateConnectionCellView、magnetS、cellViewT、magnetT、end、linkView功能。本教程显示了以下用法:。在您的情况下,您将使用类似“未测试”的内容:
var paper = new joint.dia.Paper({
validateConnection: function(cellViewS, magnetS, cellViewT, magnetT, end, linkView) {
// Only rectangle can be the source, if it is not, we do not allow such connection:
if (cellViewS.model.get('type') !== 'basic.Rect') return false;
// Only circle can be the target, if it is not, we do not allow such a connection:
if (cellViewT.model.get('type') !== 'basic.Circle') return false;
// Connection is allowed otherwise.
return true;
},
...
})
再次感谢戴夫,我用过了。再次感谢戴夫,我用过了。