Allow ext grid to load XML strings of pages

Source: Internet
Author: User

Project has special requirements: There is an applet on the page, which is responsible for retrieving data from some clients to the page. The data format is an XML string.

After reading these XML strings in JS on the page, they must be displayed in the gird of Ext.

The problem is: whether in the ext example or in the document, the XML Information loaded by the grid store is stored in an XML file. Only data in array or JSON format on the page is accepted by store. xml strings or DOM objects are not directly loaded.

Later, I found the answer in the extjs official forum. The solution is to encapsulate the XML string into a DOM object, and then use Ext. Data. memoryproxy as the proxy.

The excerpt is as follows:

 

// Load XML as string
VaR Strxml =   " <Tags> </tags> " ;
VaR Xmlobject;


// Load XML string code for IE
If (Window. activexobject)
{
VaR Doc = New Activexobject ( " Microsoft. xmldom " );
Doc. async = " False " ;
Doc. loadxml (strxml );
}
// Load XML string code for Mozilla, Firefox, opera, etc.
Else
{
VaR Parser = New Domparser ();
VaR Doc = Parser. parsefromstring (strxml, " Text/XML " );
}

Xmlobject = Doc.doc umentelement;

//

VaR Datastore =   New Ext. Data. Store ({

Proxy: New Ext. Data. memoryproxy (xmlobject ),

Reader: New Ext. Data. xmlreader ({
Record: ' Item ' ,
ID: ' Itemid '
},[
' Cat1 ' , ' Cat2 ' , ' Cat3 ' , ' Cat4 '
])
});

//Etc. etc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.