【发布时间】:2020-07-09 22:08:05
【问题描述】:
我在我的 react 应用程序中集成了 mxGraph(mxgraphnpm 包),所以当我尝试使用 xml 加载图形时,我在控制台中遇到错误
TypeError: geo.clone is not a function
我在单个 html 文件中所做的相同,它正在工作。
我调查发现,react 应用中的mxCell 与 html 不同。
如果是 HTML,则填充 geometry prop 而不是 react(检查下面的屏幕)
有人帮我正确解码 xml 吗?
从单个 HTML 控制台解码 mxCell: https://monosnap.com/file/yAHAi29zFGFpauqU2RtDcvmfPpZ0YJ
从 React 应用程序控制台解码 mxCell: 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);
【问题讨论】: