0

我最近在 Sencha 中启动了一个与现有 Web 服务接触的项目。作为该技术的新手,我在完成某些功能时面临某些问题。

问题我必须加载嵌套在 json 响应中的内容 xml,请求如下:

              load: function(me, records, successful, operation, eOpts) {
            Ext.data.JsonP.request({
                url: 'My-url-site',
                params: {
                    format: 'jsonp'
                },
                success: function(result) {
                   var xml = result.configuration; 
                    var oParser = new DOMParser();
                    var data = oParser.parseFromString(xml, "text/xml");
                    console.log(data );  // i get a pure xml content ( <?xml version="1.0"?>.....) here but i need to save it into a file .xml to use it in a store , or to parse the string using some function in sencha touch  i guess 
                }
            });
           }

我的回应:(带有 xml 内容的 json 文件)

 {"status":"ok","configuration":"<?xml version=\"1.0\"?>\n<application id=\"1\"    name=\"Kat\" color=\"#1a7892\" scdcolor=\"#666666\" language_id=\"ca\">
 <modules>
  <module id=\"32\" type=\"Home\"><application_params><param name=\"is_active\"    value=\"1\"\/><param name=\"order\" value=\"0\"\/><param name=\"menu_icon\" value=\"ico_home\"\/><param name=\"menu_text\" value=\"Home+CA\"\/><param   name=\"headlines\" value=\"1\"\/><\/application_params>
 <\/module>
 <module><\/module>
<module><\/module>
 <module><\/module>
  <\/modules>
 <\/application>\n"}

Ext.encode(xml) 不起作用,是否有将 xml 字符串转换为 json 的功能?或将我的字符串保存到文件 .xml 以便在本地与商店一起使用它?

4

1 回答 1

0

也许我遗漏了一些东西,如果您需要做的只是加载数据,您可以使用 xml 代理定义存储,该代理将自动填充您的模型。

请参阅Ext.data.proxy.Proxy - 类型 xml

编辑:

您可以尝试为您的字段创建转换函数。在您的模型中:

fields : [{
    name : 'configuration',
    convert : function(value, record) {
        // I'm not sure about this, I have never used a reader in this way but it looks possible.

        var reader = new Ext.data.reader.Reader({
            // See [config][3]
        });

        reader.read();
        // or
        reader.readReacord();

        // Then set your records with the data from the 
    }
}]

同样,这不是我用过的东西,但从文档来看它看起来很有希望。

如果您遇到任何障碍,请告诉我。

于 2013-06-24T16:22:17.977 回答