Ext.data.Store is the standard middleware used for data exchange and data interaction in ExtJS, whether it is a grid or a ComboBox, through which data reading, type conversion, sorting, paging, and searching are performed.
Ext.define (' User ', { extend: ' Ext.data.Model ', fields : [ {name: ' LoginName ', type: ' String '}, {name: ' IP ', type: ' String '} ]});
Store can read data from the local array, can also read data remotely from the server, of course, can also be read by the server Proxy, which are implemented by proxy, as to what is the distinction, and the implementation of the way will be described in the next section
To better understand the use of the store, we do the following example
var store = ext.create (' Ext.data.Store ', { model: ' User ', proxy: { type: ' Memory ', data:[{loginname: ' Admin ', IP: ' 192.168.1.2 '},{loginname: ' guest ', IP: ' 192.168.1.5 '}] }, //autoload:true//configured to indicate that the dataset is automatically loaded}) ;
Some common methods
Load Data store.load ();//Add Data Store.add ({loginname: ' administrator.com ', IP: ' 192.168.1.8 '});//Read Data Store.each (function (record) {Console.info (Record.get (' loginname ')); alert (Record.get (' loginname '));}); /Filter//store.filter ("LoginName",/\.com$/); Filter by a single domain (field): Store.filter ([ {property: ' LoginName ', Value:/\.com $/}, {filterfn:function (item) {return item.get ("IP") = = ' 192.168.1.5 ';}]); /Find a record of var record = Store.find (' LoginName ', ' guest ');//Get a quick Method for the first record in the store. var record = Store.first ();// Gets the record at the specified index var record = Store.getat (2);//Get the number of records in store var count = store.getcount;//Quick way to get the last record in the store var record = Store.last ();
EXTJS4 Learning (vii) the store in MVC