2

我正在使用 gojs 创建类图并获取 json 模型数据,我知道您可以从 xml 中读取它,有没有办法使用 XML DOM 将其写入 xml?谢谢

jQuery.ajax({ url: "class.xml", 成功: 加载, dataType: "xml" });

函数加载(x) { var xml = jQuery(x.xml ? x.xml : x); classd.model = new go.GraphLinksModel(xml.find("node").toArray(), xml.find("link").toArray());

}

4

1 回答 1

0

GoJS 默认只支持读写 JSON 模型。如果您想读取和写入 XML,您需要使用常规 JavaScript 对象并实现您自己的与 XML 之间的持久性。

这里有一个从 XML 加载的非常简单的示例:http: //gojs.net/latest/samples/minimalXML.html

它确实:

    // The previous initialization is the same as the minimal.html sample.
    // Here we request XML-format text data from the server, in this case from a static file.
    jQuery.ajax({
      url: "minimal.xml",
      success: load,
      dataType: "xml"
    });
  }

  function load(x) {
    // ought to handle parse errors here:
    var xml = jQuery(x.xml ? x.xml : x);
    // this does direct binding to XML DOM elements:
    myDiagram.model = new go.GraphLinksModel(xml.find("node").toArray(), xml.find("link").toArray());
    // such binding is read-only at the current time
  }
于 2015-05-21T19:58:59.343 回答