ExtJs4 learning Store in MVC
Ext. data. store is a standard middleware used in extjs for data exchange and data interaction. Both Grid and ComboBox use it to perform data read, type conversion, sorting paging, and search operations.
Ext.define('User', { extend: 'Ext.data.Model', fields: [ {name: 'loginname', type: 'string'}, {name: 'ip', type: 'string'} ]});
Store can read data from the local array or remotely from the server. Of course, it can also be read by the server proxy, which must be implemented by proxy. What are the differences, and the implementation method will be described in the next section
To better understand the usage of Store, we will give the following example:
Var store = Ext. create ('ext. data. store', {model: 'user', proxy: {type: 'memory ', data: [{loginname: 'admin', ip: '100. 168.1.2 '}, {loginname: 'guest', ip: '2017. 168.1.5 '}]}, // autoLoad: true // This item is configured, indicating that the dataset is automatically loaded });
Common Methods
// Load the data store. load (); // Add Data store. add ({loginname: 'administrator. com ', ip: '2017. 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 attribute field: store. filter ([{property: "loginname", value :/\. com $/}, {filterFn: function (item) {return item. get ("ip") = '20180101. 168.1.5 ';}}]); // find a record var record = store. find ('loginname', 'Guest '); // a shortcut to obtain the first record in the store. var record = store. first (); // obtain the record var record = store at the specified index. getAt (2); // obtain the number of records in the store var count = store. getCount; // The shortcut for obtaining the last record in the store. var record = store. last ();