Document directory
- 1. Ext. Data. Connection
- Ii. Ext. Data. Record
- Iii. Ext. Data. Store
- Iv. Summary
Ext. Data defines a series of store, reader, and proxy in The namespace. Both grid and comboxbox use Ext. data as the media to obtain data. It includes asynchronous loading, type conversion, paging, and other functions. EXT supports data formats such as array, JSON, and XML by default. Data in these formats can be obtained through memory, HTTP, and scripttag. To implement new protocols and new data structures, you only need to extend reader and proxy. This chapter mainly introduces data storage and transmission in ext.
1. Ext. Data. Connection
Ext. data. connection is mainly used in ext. data. httpproxy and ext. data. the scripttagproxy executes the task of interacting with the background. It obtains data from the specified URL and delivers the data returned by the background to httpproxy or scripttagproxy for processing. Ext. data. the usage of connection is shown below:
(1) Create a New Ext. Data. Connection instance.
VaR conn = new Ext. data. connection ({<br/> autoabort: false, <br/> defaultheaders: {<br/> Referer: 'http: // www.sina.com.cn '<br/> }, <br/> disablecaching: false, <br/> extraparams :{< br/> name: 'name' <br/>}, <br/> method: 'get ', <br/> Timeout: 300, <br/> URL: '01-01.txt '<br/> });
(2) After creating a Conn, you can call the request () function to send a request to process the returned results.
Conn. request ({<br/> success: function (response) {<br/> Ext. MSG. alert ('info', response. responsetext); <br/>}, <br/> failure: function () {<br/> Ext. MSG. alert ('warn', 'failed'); <br/>}< br/> });
(3) Ext. data. connection also provides the abort ([number transactionid]) function. When multiple requests occur at the same time, one of the requests is abandoned Based on the specified transaction ID. If no ID is specified, the last request is discarded.
Ii. Ext. Data. Record
Ext. Data. Record is an object that sets the internal data type. It is the most basic component of Ext. Data. Store. The main function of Ext. Data. Record is to save data and record the modification status when internal data changes. It can also retain the original value before modification.
(1) When we use Ext. Data. Record, we usually start with the CREATE () function. First, we use the CREATE () function to create a custom recore type, as shown below:
VaR personrecord = ext. data. record. create ([<br/> {Name: 'name', type: 'string'}, <br/> {Name: 'sex', type: 'int'} <br/>]);
(2) personrecord is the new type we define. Then we use the new keyword to create an instance of personrecord:
VaR boy = new personrecord ({<br/> name: 'boys', <br/> sex: 0 <br/> });
(3) Now we get the personrecord instance boy. How can we get its property value? There are three methods:
Alert (boy. data. name); <br/> alert (boy. data ['name']); <br/> alert (boy. get ['name']);
Iii. Ext. Data. Store
Ext. data. store is the standard middleware used in ext for data exchange and data interaction. Both grid and combox use it to perform data read, type conversion, sorting, and search operations. Ext. Data. Store has an Ext. Data. Record array. All data is stored in these Ext. Data. record instances to prepare for subsequent read and modification operations.
(1) Before use, create an Ext. Data. Store instance, as shown in the following code:
VaR DATA = [<br/> ['Boy ', 0], <br/> ['girl', 1] <br/>]; <br/> var store = new Ext. data. store ({<br/> Proxy: New Ext. data. memoryproxy (data), <br/> reader: New Ext. data. arrayreader ({}, personrecord) <br/>}); <br/> store. load ();
(2) Each store must support at least two components: proxy and reader. Proxy is used to read the original data from a certain channel, and reader is used to convert the original data to a record instance.
Iv. Summary
This chapter mainly introduces Ext. data. record and ext. data. store functions and basic usage methods. These two classes are combined to form Ext. many of the main data models in data are built on them. Other common proxies, reader, store: simplestore, and jsonstore are described in detail later.