我使用以下代码来控制链接上的删除功能。如果链接符合特定条件,如何拦截remove事件并阻止它?
// add a remove button on hovered link
this.paper.on("link:mouseenter", function(linkView) {
let tools = [new joint.linkTools.Remove({ distance: 20 })];
linkView.addTools(
new joint.dia.ToolsView({
name: "onhover",
tools: tools
})
);
});
// remove button on hovered link
this.paper.on("link:mouseleave", function(linkView) {
if (!linkView.hasTools("onhover")) return;
linkView.removeTools();
});
答案 0 :(得分:1)
使用传递给linkTools.Remove构造函数的action参数找到了答案。
// add a remove button on hovered link
this.paper.on("link:mouseenter", function(linkView) {
let tools = [
new joint.linkTools.Remove({
distance: 20,
action: function(evt) {
// do stuff and remove link using
this.model.remove({ ui: true, tool: this.cid });
}
})
];
linkView.addTools(
new joint.dia.ToolsView({
name: "onhover",
tools: tools
})
);
});