您也可以按照您想要的方式定义视图,然后在论文中定义要使用的链接视图,如 api http://jointjs.com/api#joint.dia.Paper
传递给构造函数的选项对象可能包含以下属性:
...
* linkView - object that is responsible for rendering a link model into the paper. Defaults to joint.dia.LinkView
* defaultLink - link that should be created when the user clicks and drags and active magnet (when creating a link from a port via the UI). Defaults to new joint.dia.Link
...
然后,查看https://github.com/DavidDurman/joint/blob/master/src/joint.dia.link.js的 GitHub 源代码,查找pointerdown。这是我的结果:
// custom element for link
// ---------------------------------------------------------------------------
joint.shapes.customLink = {};
joint.shapes.customLink.Element = joint.dia.Link.extend({
defaults: joint.util.deepSupplement({
type: "customLink.Element",
attrs: {},
}, joint.dia.Link.prototype.defaults),
});
joint.shapes.customLinkView = joint.dia.LinkView.extend({
pointerdown: function (evt, x, y) {
var targetParentEvent = evt.target.parentNode.getAttribute("event");
if (targetParentEvent && targetParentEvent === "remove") {
// YOUR STUFF HERE FOR REMOVE
} else {
joint.dia.LinkView.prototype.pointerdown.apply(this, arguments);
}
},
});