mxGraph -Save functionality not working locally

前端 未结 2 743
天涯浪人
天涯浪人 2020-12-10 08:50

I downloaded https://github.com/jgraph/mxgraph open source code from Git,this application Save functionality not working in the locally. Is there any possible for run the sa

相关标签:
2条回答
  • 2020-12-10 09:00

    You can save locally by using the mxCodec class found in the IO package. Check out the example code here. I'm not sure how to tie it into that specific button, but find the function that is called when you click save and add/replace it with the three lines needed to encode as xml.

    As for how to get that xml code to save as a file, I'm not sure. Perhaps you'll find that code when you modify the save button functionality. The easy way would be to create a div and replace its innerhtml with the xml data, then just copy it and save it yourself.

    0 讨论(0)
  • 2020-12-10 09:19

    I provide the code snippets for local save && upload of the saved file

    code to export the xml of the current graph object

    let encoder = new mxCodec();
    let result = encoder.encode(graph.getModel());
    let xml = mxUtils.getXml(result);
    //workaround for the xml export, do not include the <mxGraphModel> tags
    xml = xml.substring(xml.indexOf("<mxGraphModel>")+"<mxGraphModel>".length, xml.indexOf("</mxGraphModel>"));
    

    code to upload the xml to re-generate the saved state of the graph

    let doc = mxUtils.parseXml(xml);
    let codec = new mxCodec(doc);
    codec.decode(doc.documentElement, graph.getModel());
    let elt = doc.documentElement.firstChild;
    let cells = [];
    while (elt != null)
    {   
        let cell = codec.decode(elt)
        if(cell != undefined){
                if(cell.id != undefined && cell.parent != undefined && (cell.id == cell.parent)){
                    elt = elt.nextSibling;
                    continue;
                }
                cells.push(cell);
        }
        elt = elt.nextSibling;
    }
    graph.addCells(cells);
    
    0 讨论(0)
提交回复
热议问题