我想通过双击链接来为链接添加标签。所以这是我的尝试:
paper.on({
'cell:pointerdblclick': function(cellView, event, x, y){
if (cellView.model.isLink()) {
cellView.model.label(0, {
position: .5,
attrs: {
rect: { fill: 'white' },
text: { text: 'my label' }
}
});
}
},
});
问题是,通过双击还会同时创建一个顶点。我怎样才能防止这种情况发生?
或者让用户为链接添加标签的另一种简单方法是什么?
最佳答案
如文档 ( http://jointjs.com/api#joint.dia.LinkView:addVertex ) 所示,只需将此部分添加到 joint.dia.Paper
:
interactive: function(cellView) {
if (cellView.model instanceof joint.dia.Link) {
// Disable the default vertex add functionality on pointerdown.
return { vertexAdd: false };
}
return true;
}
关于javascript - jointjs:防止通过单击链接添加顶点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33322627/