Store is a storage container that provides record objects for ext devices. Its behavior and attributes are similar to data tables.
Method: do not list inherited methods
Store (Object config)
Constructor. config is defined {
Autoload: Boolean/object, // automatically load
Baseparams: object, // meaningful only when httpproxy is used
Data: array, // data
Proxy: Ext. Data. dataproxy, // data proxy
Prunemodifiedrecords: Boolean, // clear the modification Information
Reader: Ext. Data. Reader, // data reader
Remotesort: Boolean, // remote sorting?
Sortinfo: object, // {field: "fieldname", direction: "ASC | DESC "}
URL: String, // construct httpproxy using URL
}
Add (ext. Data. Record [] records): void
Add records to store
Addsorted (ext. Data. Record record): void
Add record to store and sort (only available for local sorting)
Clearfilter (Boolean suppressevent): void
Clear Filter
Collect (string dataindex, [Boolean allownull], [Boolean bypassfilter]): Array
Collects the unique values of fields specified by dataindex.
Commitchanges (): void
Submitting all changes to the store will trigger an update event.
Filter (string field, string/Regexp value, [Boolean anymatch], [Boolean casesensitive]): void
Set Filter
Field: String // field name
Value: String // If Regexp is a character generator, check whether the field starts with value. If it is a regular expression, check whether the field matches.
Anymatch: Boolean // matches any part, not only the start
Casesensitive: Boolean // case sensitive?
Filterby (function FN, [object scope]): void
More powerful filtering method. FN receives two parameters record and ID
Find (string property, string/Regexp value, [number startindex], [Boolean anymatch], [Boolean casesensitive]): Number
Find the first record that meets the condition. The parameter is the same as that of filter.
Findby (function FN, [object scope], [number startindex]): Number
See filterby
Getat (number index): Ext. Data. Record
Getbyid (string ID): Ext. Data. Record
Obtain the record object based on the filling number/ID.
Getcount (): void
Number of records obtained
Getmodifiedrecords (): Ext. Data. Record []
Get the modified record set
Getrange ([number startindex], [number endindex]): Ext. Data. Record []
Obtains the set of records within the specified range.
Getsortstate (): void
Get the sorting status: it is obviously not void but returns a sorting object, with the same structure as sortinfo {field: "fieldname", direction: "ASC | DESC "}
Gettotalcount (): void
This is useful for paging information.
Indexof (ext. Data. Record record): Number
Indexofid (string ID): Number
Obtain the serial number from the record or ID
Insert (number index, ext. Data. Record [] records): void
Inserts records at the specified position and triggers the Add event.
Isfiltered (): Boolean
If a filter is set, the returned result is true.
Load (Object options): void
The specified proxy uses the specified reader to read remote data.
Options is defined
{
Params: object, // parameters to be attached to the request URL
Callback: function // call back method, which receives three parameters
// R: Ext. Data. Record [] // returned record Array
// Options: Options imported by the options Load Method
// Success: Boolean // success
Scope: object, // range. The default value is store.
Add: Boolean append or update
}
Loaddata (Object Data, [Boolean append]): void
It is easier to use than load for the same purpose, but the data is read locally.
Query (string field, string/Regexp value, [Boolean anymatch], [Boolean casesensitive]): mixedcollection
Queryby (function FN, [object scope]): mixedcollection
Query. The parameters are similar to find, but all matching records are returned, instead of the sequence number of the first matching record.
Rejectchanges (): void
Discard all changes
Reload ([object options]): void
Re-load is equivalent to load (options, false). If no options is input, take the parameter used in the last load.
Remove (ext. Data. Record record): void
Remove a specified record
Removeall (): void
Remove all records
Setdefaultsort (string fieldname, [String dir]): void
Set Default sorting rules
Sort (string fieldname, [String dir]): void
Sort
Sum (string property, number start, number end): Number
Sum the property field from start to end
Event list
Add: (store this, ext. Data. Record [] records, number index)
Beforeload: (store this, object options)
Clear: (store this)
Datachanged: (store this)
Load: (store this, ext. Data. Record [] records, object options)
Loadexception :()
Metachange: (store this, object meta .)
Remove: (store this, ext. Data. Record record, number index)
Update: (store this, ext. Data. Record record, string operation)
It is easy to look at the name, and the parameters are not complex.
Use Cases
// Obtain the remote JSON object
// The content of jsoncallback. JS is
// {'Results': 2, 'rows ':[
// {'Id': 1, 'name': 'Bill ', Occupation: 'gardener '},
// {'Id': 2, 'name': 'ben', Occupation: 'horticulturalist'}]
//}
// Define proxy
VaR proxy = new Ext. Data. httpproxy (... {URL: 'jsoncallback. js '});
// Define Reader
VaR reader = new Ext. Data. jsonreader (
...{
Totalproperty: "Results", // The totalrecords property is obtained by JSON. Results.
Root: "rows", // The array for constructing metadata is obtained by JSON. rows.
ID: "ID" // ID is obtained by JSON. ID
},[
... {Name: 'name', mapping: 'name '},
... {Name: 'occupation'} // if the name and mapping have the same name, you can omit mapping.
]
)
// Create a store
VaR store = new Ext. Data. Store (...{
Proxy: proxy,
Reader: Reader
});
// Load
Store. Load ();
Example 2
// obtain the remote XML file
// Where the XML file content is
2
1
bill
gardener
2
Ben
horticulturalist
var proxy = new Ext. data. httpproxy (... {URL: 'datasource. xml'});
var reader = new Ext. data. xmlreader (... {
totalrecords: "Results",
record: "row",
ID: "ID"
}, [
... {Name: 'name', mapping: 'name'},
... {Name: 'occupation'}
]);
var store = new Ext. data. store (... {
Proxy: proxy,
reader: reader
});
store. load ();
Example 3
// obtain from the local array
var arr = [[1, 'bill ', 'gardener'], [2, 'ben', 'horticulturalist'];
var reader = new Ext. data. arrayreader (
{ID: 0},
[
{Name: 'name', mapping: 1},
{Name: 'occupation ', mapping: 2}
]);
var store = new Ext. data. store ({
reader: reader
});
store. loaddata (ARR);