我想添加一个按钮以将当前图表导出到 xml var。
我知道有一个按钮可以导出,但我不明白它用来导出的代码。
我是编码新手,所以请帮忙。
您可以使用以下代码将graph
对象的当前状态保存到:xml format
var xml = "";
let saveBtn = document.createElement('button');
saveBtn.value = ' Save XML ' ;
saveBtn.addEventListener('click',function(e){
exportXML(); //on click trigger the exportXML() function;
});
function exportXML() {
let encoder = new mxCodec();
let result = encoder.encode(graph.getModel()); //where graph is the object you are using
xml = mxUtils.getXml(result); //now the global variable 'xml' is assigned with the xml value of the graph
}