I have read more than N documents and read many forums over the past two days. I plan to solve the problem of reading data from the store. At the beginning, I can read data from the store returned in Json, however, xml cannot be used. what I want is how to read data from xml, so I have been looking for such a similar method. We can see store from its api. getAt (0) method, but if we use this method directly, an error occurs, prompting that the data contained in the getAt function is null, therefore, we cannot obtain specific data when tracking js. here, firefox is used to track the execution process of js, which is very easy to use. We recommend that you also use it. for Ext, its documentation may be a reference for people who are very familiar with Ext. For Beginners, the reference is of little value, and sometimes it is easy to mislead, so we are always in a bumpy state when learning Ext. or this is why people will pay for it in the future. After all, it is an open-source item, and the attributes and Methods prompted by Ext documents are correct.
Today, I accidentally found a post with the same problem as me In the Ext Forum. Finally, he solved the problem and I also solved it by the way. but he didn't paste his code, so I am pasting my code for reference.
This is an Xml document
<? Xml version = "1.0" encoding = "UTF-8"?>
<Items>
<Item input = "Connect. Host" value = "value. Connect. Host"/>
<Item input = "Connect. DB" value = "value. Connect. DB"/>
<Item input = "Connect. User" value = "value. Connect. User"/>
<Item input = "Connect. Password" value = "value. Connect. Password"/>
</Items>
The following is the js Code:
Var ds = new Ext. data. Store ({
Proxy: new Ext. data. HttpProxy ({url: 'test1. xml', method: 'get '}),
Reader: new Ext. data. XmlReader (
// Records will have an "Item" tag
{Record: 'item '},
[
// Set up the fields mapping into the xml doc to extract * attributes *
{Name: 'value', mapping: '@ value '},
{Name: 'input', mapping: '@ input '}
])
});
Ds. on ('load', AJAX_Loaded, this, true); // note this
Ds. load ();
Function AJAX_Loaded (){
Alert (ds. getCount ());
For (var I = 0; I <ds. getCount (); I ++ ){
Var rec = ds. getAt (I );
Alert ("value = '" + rec. get ("value "));
Alert ("input = '" + rec. get ("input "));
}
}
It should be noted that the data we get is implemented through the load event, which is a lot of errors. That is to say, if we do not get data through the event, we still cannot get data.