Notes for extjs store

Source: Internet
Author: User
Tags dname

Store, or data storage, is mainly used for providing gridpanel, editorgridpanel, and other associated data.

Store is composed of a proxy (data source) and a datareader (Data parser.

Store contains multiple Ext. Data. Record objects

In other words:
1. Data Storage requires data to be called data storage, which is obtained from the data source;
2. After obtaining the data, you also need to use the data parser to parse the data, so as to become the data in a certain format recognized by the client.
With the preceding two conditions, this data storage can truly serve gridpanel and other services.

Now let's take a look at how store works:
To view the API, we only need to care about its four configuration options: data, proxy, reader, URL
And one of its methods: Load

1. if data is configured, the proxy and URL are invalid and you do not need to call the load method to generate a record set.

2. if data is not configured, you must set proxy or URL or both. If autoload is not set to true, you need to call the load method manually. To obtain data in array, JSON, or XML format.

3. Reader is required to specify the data parser. You need to specify the corresponding type of parser Based on the obtained data format.

4. If no proxy is specified but a URL is specified, httpproxy is used as the data source by default and the URL is used as the parameter during httpproxy instantiation.

5. If data encapsulates data in array format, arrayreader is used as the parser, that is, the following configuration is required during store instantiation:

JS Code
  1. Reader: New Ext. Data. arrayreader ({...});



6. If data is encapsulated in JSON format, jsonreader is used as the parser, that is, the following configuration must be made during stroe instantiation:
JS Code

  1. Reader: New Ext. Data. jsonreader ({...});



7. If data encapsulates data in XML format, xmlreader is used as the parser, that is, the following configuration must be performed during store instantiation:
JS Code

  1. Reader: New Ext. Data. xmlreader ({...});

8. If the data in the store is modified, you can use the store. commitchages () or record. commit () can be used to modify data or restore the previous data store. rejectchages () or record. reject (). Note: It can be restored without submission.

The following is a store example: Note: store. baseparams = {AA: 'B '}

Ext. onready (function () {var proxy = new Ext. data. httpproxy ({URL: '/my_extjs/Login-query.action', method: 'post'}); var myreader = new Ext. data. jsonreader ({idproperty: 'deptno', root: 'data', // key totalproperty: 'Total' of the corresponding background data, // total number of attribute records corresponding to the background, not the total number of pages fields: [// you can also use Ext. data. record. create to create {Name: 'deptno', mapping: 'deptno'}, // mapping is the value of the JSON object transmitted from the background, {Name: 'dname', mapping: 'dname'}, {Name: 'loc ', ing: 'loc'}]}); var store = new Ext. data. store ({Proxy: proxy, storeid: 'mystore', Reader: myreader}); store. load ({Params: {start: 0, limit: 2}, callback: function (R, OPS, success) {// when success is set to 200 // store. each (function (record) {// alert (record. get ('deptno'); //}); // var newrecord = new Ext. data. record ({name: "Tom", age: 22}); // store. add (newrecord); // store. insert (3, newrecord); alert (store. getcount () + "" + store. gettotalcount (); // alert (store. getat (3 ). get ('name'); // get record. get ('name')}); // alert (store. getcount (); // when the access to the background is not returned, it has been run, so it is 0 });

The store. Load () method should be loaded after the grid to trigger loadmask.

Configure the API in httpproxy

Ext. Data. API. Actions ['read'] = 'load ';

Proxy: New Ext. Data. httpproxy ({
// Method: 'get ',
// URL: path + '/servlet/my_servlet'
API :{
'Load ':{
'Method': 'post ',
URL: path + '/servlet/my_servlet'
}
}
})

If you modify a record in the store,

Alert (mystore. getat (0). Get ('mid '));

Mystore. getat (0). Set ('mid ',' AB ');

Alert (mystore. getmodifiedrecords () [0]. Get ('mid '));

From: http://yahaitt.iteye.com/blog/234409

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.