问题
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