beforeItemCatch
描述
在项目被捕获之前触发
信息
该事件仅在 Diagram 的组织结构图和 mindmap 模式下有效,且必须将 itemsDraggable 属性设置为 true。
用法
"beforeItemCatch": ({
id: string | number,
targetId: string | number,
batch: (string | number)[],
event: PointerEvent
}) => boolean | void;
参数
该事件的回调函数使用一个包含以下参数的对象进行调用:
id- 被移动项目的 idtargetId- 目标项目的 idbatch- 已移动元素 id 组成的数组event- 事件对象
返回值
回调函数返回 false 以阻止项目被捕获;否则返回 true
信息
要处理 Diagram Editor 的内部事件,您可以使用 on() 方法。
示例
// initializing Diagram Editor
const editor = new dhx.DiagramEditor("editor_container");
// loading data
editor.parse(data);
// attaching a handler to the event
editor.events.on("beforeItemCatch", ({ id, targetId }) => {
if (targetId === "2.1"){
console.log(`
Item ${id} won't be be caught by the item "2.1"
`);
return false;
}
else{
console.log(`
Item ${id} will be caught by the item ${targetId}
`);
return true;
}
});
更新日志:
batch参数已在 v6.0 中新增- 自 v6.0 起,回调函数以对象作为参数