reactjs - mxCodec 无法正确解码 xml
问题描述
我在我的反应应用程序中集成了 mxGraph(mxgraph
npm 包),所以当我尝试使用 xml 加载图形时,我在控制台中收到错误
TypeError: geo.clone is not a function
我在单个 html 文件中所做的相同,它正在工作。
我调查并发现mxCell
in react 应用程序与 html 应用程序不同。
在 HTML 的情况下,有填充geometry
道具而不是反应(检查下面的屏幕)
Сan有人帮我正确解码xml吗?
mxCell
从单个 HTML 控制台解码: https ://monosnap.com/file/yAHAi29zFGFpauqU2RtDcvmfPpZ0YJ
mxCell
从 React 应用程序控制台解码: https ://monosnap.com/file/0XxPwyEracX7hMCnMHckAmI8Rl6OEh
React 组件的源代码:
const graph = new mx.mxGraph(this.automationRef.current)
new mx.mxRubberband(graph);
const xml = '<root>...</root>';
const doc = mx.mxUtils.parseXml(xml);
const codec = new mxCodec(doc);
let elt = doc.documentElement.firstChild;
const cells = [];
while (elt != null){
const cell = codec.decodeCell(elt)
cells.push(cell);
graph.refresh();
elt = elt.nextSibling;
}
graph.addCells(cells);
解决方案
发现问题。这是解决方案:
https://github.com/jgraph/mxgraph/issues/301#issuecomment-514284868
引用:
你应该添加
window['mxGraphModel'] = mxGraphModel;
window['mxGeometry'] = mxGeometry;
前
let doc = mxUtils.parseXml(xml);
let codec = new mxCodec(doc);
codec.decode(doc.documentElement, graph.getModel());'
我发现解码方法解析xml需要windows param
结束报价
推荐阅读
- c# - 调用函数后隐式调用函数
- spring - 根据 ReloadableResourceBundleMessageSource 中的请求标头设置基本名称
- reactjs - REACT:如何告诉父组件来自子组件的无效数据?
- javascript - 理解涉及 `arguments` 的 `this` 行为
- c# - 当我尝试登录我的应用程序“ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK)”时,我的浏览器抛出此错误
- java - 有没有 Jansi jar 用于颜色 cosole 输出的替代品?
- javascript - 单击可滚动div内的视频按钮,将其向右移动
- java - Java 中的类声明与 Kotlin 中的类声明
- javascript - 悬停播放视频
- json - 验证 Json - Laravel