Ext. Data-datareader/arrayreader/jsonreader/xmlreader

Source: Internet
Author: User
Ext. Data. datareader
A pure virtual class that converts structured data from a data source to a metadata object. An object contains a record set, which is generally used as the metadata of a store object,
Has the following format
{
Totalrecord: int,
Records: array of Ext. Data. Record
}
For more information, see the three subclasses.
Ext. Data. arrayreader/EXT. Data. jsonreader/EXT. Data. xmlreader

Method
Datareader (object meta, object recordtype)
Structure

Ext. Data. arrayreader
Used to read an array to a metadata object.

Arrayreader (object meta, object recordtype)
Construction. The first parameter is the configuration, except that it can indicate which field is used for ID, and does not understand other usage,
The second parameter is the same as the parameters of the create method of the record object and the config object array. For details, see
Readrecords (Object O): Object
Reads O and returns a metadata object.

Example:
// Define an array
VaR arr = [[1, 'bill ', 'gardener'], [2, 'ben', 'horticulturalist'];
VaR reader = new Ext. Data. arrayreader (
// Use the first element as the recordid
{ID: 0 },
// Define the ing between arrays and record
[
{Name: 'name', mapping: 1 },
{Name: 'occupation', mapping: 2}
]
);
// Generate metadata
VaR DATA = reader. readrecords (ARR );

Ext. Data. jsonreader
Converts a JSON object to a metadata object.

Jsonreader (object meta, object recordtype)
The jsonreader construction parameter meta can have more options,
{
ID: string,
Root: string,
Successproperty: string,
Totalproperty: String
}
Are the attribute names corresponding to the JSON object.

Read (Object response): Object
Returned from a response object. The response. responsetext attribute should contain only one JSON data block.

Readrecords (Object O): Object
Reads O and returns a metadata object.

Example:
VaR JSON = {'results': 2, 'rows ':[
{'Id': 1, 'name': 'Bill ', Occupation: 'gardener '},
{'Id': 2, 'name': 'ben', Occupation: 'horticulturalist'}]
};
VaR reader = new Ext. Data. jsonreader (
{
Totalproperty: "Results", // The totalrecords property is obtained by JSON. Results.
Root: "rows", // The array for constructing metadata is obtained by JSON. rows.
ID: "ID" // ID is obtained by JSON. ID
},[
{Name: 'name', mapping: 'name '},
{Name: 'occupation'} // if the name and mapping have the same name, you can omit mapping.
]
)
VaR DATA = reader. readrecords (JSON );

Ext. Data. xmlreader
Of course, xmlreader objects are prepared for XML.

Structure:
Xmlreader (object meta, mixed recordtype)
Meta is similar to jsonreader,
Meta is {
ID: string,
Record: string,
Success: string,
Totalrecords: String
} Object, but these strings are relative to the domquery path of the document root directory
Read (Object response): Object
Readrecords (Object DOC): Object
....

VaR STR = ["<? XML version = \ "1.0 \" encoding = \ "UTF-8 \"?> ",
"<Dataset> ",
"<Results> 2 </Results> ",
"<Row> ",
"<ID> 1 </ID> ",
"<Name> Bill </Name> ",
"<Occupation> gardener </occupation> ",
"</Row> ",
"<Row> ",
"<ID> 2 </ID> ",
"<Name> Ben </Name> ",
"<Occupation> horticulturalist </occupation> ",
"</Row> ",
"</Dataset>"]. Join ("");

// generate the xmldocument object
var xmldocument;
If (ext. isie) {
xmldocument = new activexobject ("msxml2.freethreadeddomdocument")
xmldocument. async = false;
xmldocument. resolveexternals = false;
xmldocument. loadxml (STR)
}< br> else {
xmldocument = (New domparser ()). parsefromstring (STR, "text/XML");
}

// start... similar to the other two readers, recordtype can be a record object
var record = ext. data. record. create ([
{Name: 'name', mapping: 'name '}, // "mapping" property not needed if it's the same as "name"
{Name: 'occupation'} // this field will use "Occupation" as the mapping.
])
var reader = new Ext. data. xmlreader ({
totalrecords: "Results",
record: "row", // row is the node selector
ID: "ID"
}, record);
var DATA = reader. readrecords (xmldocument);

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.