initialize mxgraph with default xml model

血红的双手。 提交于 2019-12-14 03:25:23

问题


How can I start with an existing XML model in mxgraph. I have a default XML graph and i want to import it on mxgraph load (start)


回答1:


Using the GraphEditor - Template
You can set a default mxGraphModel by appling it with setGraphXML.
The following example shows you how to apply a default mxGraphModel.

In the data-object, declare your default model as xml. Then you can parse the model with parseXml to xml and then apply it to the graph.

Implementation of setGraphXML in the GraphEditor

var data =
    '<mxGraphModel pageWidth="1169" pageHeight="827" background="#ffffff">' +
    '    <root>' +
    '        <mxCell id="0" />' +
    '        <mxCell id="1" parent="0" />' +
    '    </root>' +
    '</mxGraphModel>';
graph.model.beginUpdate();
try {
    var xml = mxUtils.parseXml(data).documentElement;
    setGraphXml(xml);
}
catch (e) {
    console.log(e);
}
finally {
    graph.model.endUpdate();
}


来源:https://stackoverflow.com/questions/54835679/initialize-mxgraph-with-default-xml-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!