简体   繁体   English

如何在ExtJS中读取本地XML文件?

[英]How to read local XML file in ExtJS?

I use ExtJS 4.2. 我使用ExtJS 4.2。 What is the easiest way to read local XML file? 读取本地XML文件的最简单方法是什么? I understand that it's possible to use store and model, but I prefer other way. 我知道可以使用商店和模型,但我更喜欢其他方式。 Is it possible to use Ext.Ajax.Request? 是否可以使用Ext.Ajax.Request?

For example, this is my XML file content: 例如,这是我的XML文件内容:

<LocaleText>
  <Item>
    <CTRO_CONTROLID>lblLoginTitle</CTRO_CONTROLID>
    <CTRO_CONTROLTYPE>label</CTRO_CONTROLTYPE>
  </Item>
    <Item>
    <CTRO_CONTROLID>cboLoginLanguage</CTRO_CONTROLID>
    <CTRO_CONTROLTYPE>combobox</CTRO_CONTROLTYPE>
  </Item>
</LocaleText>

How can I get the data of each Item node? 如何获取每个Item节点的数据?

  1. You can use the response.responseXML in the Ext.Ajax.request for getting the xml type response. 您可以使用Ext.Ajax.requestresponse.responseXML来获取xml类型的响应。
  2. and you can use the Ext.DomQuery class for getting data out from an xml 并且您可以使用Ext.DomQuery类从xml中获取数据

Example: 例:

Ext.Ajax.request({           
    url: '/your/url/here/test.xml',            
    success: function (response, options) {
        var object = response.responseXML;
        var test = Ext.DomQuery.select('Item', object);
        console.log('test', test);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM