【问题标题】:mxCodec doesn't decode xml correctlymxCodec 无法正确解码 xml
【发布时间】: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);

【问题讨论】:

    标签: reactjs mxgraph


    【解决方案1】:

    发现问题。 这是解决方案:

    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());'
    

    发现decode方法解析xml需要windows参数

    结束引用

    【讨论】:

      猜你喜欢
      • 2020-11-26
      • 2012-08-05
      • 2017-03-25
      • 2013-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-27
      • 1970-01-01
      相关资源
      最近更新 更多