【问题标题】:from gojs convert json model to xml从 gojs 将 json 模型转换为 xml
【发布时间】:2015-04-18 14:40:58
【问题描述】:

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

jQuery.ajax({ 网址:“class.xml”, 成功:加载, 数据类型:“xml” });

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

}

【问题讨论】:

    标签: javascript xml json gojs


    【解决方案1】:

    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
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-20
      • 2012-05-27
      • 1970-01-01
      • 1970-01-01
      • 2014-07-21
      • 2013-05-09
      • 1970-01-01
      相关资源
      最近更新 更多