mxGraph 工具栏事件重写----粘贴事件重写功能
最近项目需要对复制粘贴后的数据进行内容修改完善,在网络中搜索很多没有找到方法,找的都是有关于工具栏命令,自己就根据调试查看editor返回的值进行探索,还是直接上代码吧
var node = mxUtils.load(config).getDocumentElement();
editor = new mxEditor(node);
editor.toolbar.editor.actions.paste = function () { //toolbar 重写粘贴事件
if (editor.graph.isEnabled()) {
mxClipboard.paste(editor.graph);
var cells = new Array();
cells = editor.graph.getSelectionCells(); //选中的是粘贴后的数据
cells.forEach((ele) => {
let value = ele.value.attributes.taskReferenceName.value;
let index = value.lastIndexOf('_');
ele.value.attributes.taskReferenceName.value = value.slice(0, index + 1) + ele.id;
})
}
};
最后可以查看mxGraph 工具栏按钮事件大全(edit的action执行代码汇总,中文,翻译,大全):
https://blog.mn886.net/chenjianhua/show/1ef0ae001ede4b05be81621885b7ddb7/index.html