http://blog.csdn.net/without0815/article/details/7798170
1. What is a store?
Store is similar to a local repository (that is, data storage), including Arraystore,directstore,groupingstore,jsonstore,xmlstore (both store subclasses)
Ultimately, it is used primarily to provide panel display.
The store consists of a proxy (data source) and DataReader (interpreting data).
I. (PROXY) data source: Usually the background value, habitually convert it to a JSON object to the store (note: personal understanding)
Two. (DataReader) Read data: After the data is obtained, the data needs to be parsed, DataReader (The Fields property is actually the Record object) parsing the data and specifying the format.
Three. Store-stored data is finally presented to panel
Important properties and methods in 2.store
Properties: Data, proxy, reader, url, root ....
Method: Load
1. If data is configured, the proxy and URL are not valid, and you do not need to call the Load method to generate the Record collection
1 var store=New Ext.data.ArrayStore ({ 2fields : [' DEPTNO ', ' dname ', ' LOC ') ], 3 data:Ext.datas.mess // reference data.js data 4
2. If data is not configured, you must either set a proxy or URL, or both. At this point, if AutoLoad is not set to true,
Then the call to the Load method needs to be done manually. is to get data in the form of arrays, JSON, or XML.
Example: reading data in JSON format
1Ext.define ("ExtApp.store.StudentList",{2Extend: "Ext.data.Store",3Model: "ExtApp.model.UserinfoM",4Autoload:{start:0,limit:3},//Paging to use5Pagesize:3, 6 proxy:{7Type: "Ajax",8URL: ' Querystudents.action ',9 reader:{TenType: "JSON", OneRoot: "Rows", ATotalproperty: "Results" - } - } the});
Http://www.cnblogs.com/hdchild/archive/2009/11/17/1605011.html
Several ways to read data in 3.store
Arrayreader Jsonreader XmlReader
Arrayreader: This is an array type of data with the following data form:
[1, ' Test ', ' Xiao Wang ', 3], [2, ' good New Year ', ' Williamraym ', 13]]
We're going to define this type of data
var Myrecord = Ext.data.Record.create ([
{name: ' title ', mapping:1},//corresponding ' test '
{Name: ' username ', mapping:2},//corresponds to ' Xiao Wang '
{name: ' logintimes ', type:3}//corresponds to ' 3 '
]);
The mapping here is the subscript in the corresponding array, of course the following table of the array is starting from 0.
When the data type is defined, the data must be read:
var myreader = new Ext.data.ArrayReader ({
id:0
}, Myrecord);
Note that the id:0 here shows that the No. 0 column of real data is the corresponding ID. The first column corresponds to the title in the type we define, and so on.
Jsonreader:
JSON data: This is the data returned in the background:
{' Results ': 2, ' Rows ': [
{id:1, title: ' Test ', Author: ' Xiao Wang ', logintimes:3},
{id:2, title: ' Ben ', Author: ' Williamraym ', logintimes:13}]
}
We want to define our own data types:
Model layer:
var Myrecord = Ext.data.Record.create ([
{name: ' title '},
{Name: ' username ', mapping: ' Author '},the role of//mapping: corresponds to the JSON data returned, mapping and the class property in the background action correspond to
{name: ' Logintimes ', type: ' int '}
The store layer writes:
1 ext.define ("ExtApp.store.StudentList", {2 Extend: "Ext.data.Store", 3 Model: " ExtApp.model.UserinfoM ", 4 Autoload:{start:0,limit:3}, //5 Pagesize:3 for paging , 6 proxy:{7 type: "Ajax", 8 URL: ' querystudents.action ', 9 reader:{10 type: "JSON", one root: "Rows", 12 totalproperty: "Results" }15 });
What does extjs inside mapping mean?
See here, the Name property corresponds to the name of our own data column, mapping corresponds to the data column name of the real data, if the two are the same, mapping can be omitted.
XmlReader
This is very similar to JSON, basically.
First look at the original data:
<topics>
<results>2</results>
<row>
<id>1</id>
<title> Test </title >
<author> Xiao Wang </author >
<logintimes>3</logintimes >
</row>
<row>
<id>2</id>
<title> Good New Year </title >
<author> Williamraym </author >
<logintimes>13</logintimes >
</row>
</topics>
we define our own data types:
var myrecord = Ext.data.Record.create ([
{name: ' title '},
{name: ' username ', mapping: ' Author '},
{name: ' Logintimes ', type: ' int '}
]);
then read the data:
var myreader = new Ext.data.XmlReader ({
totalrecords: "Results",
record: "Rows",
ID: "id"
}, Myrecord);
Here is also a one by one correspondence relationship.
These are some of their own views, but also from the online excerpt, there is no place to hope that you point out to study together.
what does root and totalproperty defined in the store in 3.Extjs mean? Reference: http://blog.csdn.net/21aspnet/article/details/6867458
Jsonreader supports paging, which corresponds to JSON data in the following format:
Successproperty: Root: JSON data, property name of the property that holds the Recordset, Id:json data, the name of the column that corresponds to the primary key in the record
For example, the JSON data returned to the foreground in the background is shown in the following code :
JSON data
var json = {' Results ': 2,
' Rows ': [{' id ': 1, ' name ': ' Bill ', Occupation: ' Gardener '},
{' id ': 2, ' name ': ' Ben ', Occupation: ' Horticulturalist '}
]
};
Jsonreader var reader = new Ext.data.JsonReader ({totalproperty: "Resul TS ", the//totalrecords property is determined by theJson.results get successproperty:true,//json data, save whether to return the successful property name root: "Rows", Constructs an array of metadata from theJson.rows Get ID: "id" //ID byJson.id get}, [{name: ' name ', mapping: ' name '}, {name: ' Occupat Ion '}//If name is the same name as mapping , you can omit mapping]
);
Jsonreader data that is read from a proxy needs to be parsed and converted into a record array before it is available to Ext.data.Store.
In JavaScript, JSON is a very important data format, Key:value is easier to understand than the complex tag structure of XML, the code is smaller, and many people prefer to use it as the data Interchange Format for ext. The JSON data prepared for Jsonreader is shown in the following code:
var data = {
id:0,
Totalproperty:2,
Successproperty:True,
root:[
{ID:' id1 ', Name:' name1 ', Descn:' descn1 '},
{ID:' id2 ', Name:' name2 ', Descn:' descn2 '}
]
};
The biggest advantage of JSON compared to arrays is that it supports paging, and we can use the Totalproperty parameter to represent the total amount of data. The Successproperty parameter is optional and can be used to determine whether the current request is successful or not and to determine whether to load the data. You can set Successproperty to False when you do not want the jsonreader to handle the response data.
Now let's talk about Jsonreader and see how it corresponds to the JSON data above, as shown in the following code.
var reader = new Ext.data.JsonReader ({
Successproperty: "Successproperty",
Totalproperty: "Totalproperty",
Root: "root",
ID: "id"
}, [
{name: 'ID', mapping:' id '},
{name: 'name', mapping:' name '},
{name: 'descn ', Mapping:' DESCN '}
]);
Because the contents of the name and mapping sections are the same, the mapping here can be omitted, and the default is to get the corresponding data from the JSON using the name parameter. If you don't want to have the same name as in JSON, you can use mapping to modify it.
ExtJS in store small summary