Ext.data.Store是EXT中用来进行数据交换和数据交互的标准中间件,无论是Grid还是ComboBox,都是通过它实现数据读取、类型转换、排序分页和搜索等操作的。 Ext.data.Store中有一个Ext.data.Record数组,所有数据都存放在这些Ext.data. Record实例中,为后面的读取和修改操作做准备。 Ext.data.Store的基本用法 在使用之前,首先要创建一个Ext.data.Store的实例,如下面的代码所示。
- var data = [
- ['boy', 0],
- ['girl', 1]
- ];
- var store = new Ext.data.Store({
- proxy: new Ext.data.MemoryProxy(data),
- reader: new Ext.data.ArrayReader({}, PersonRecord)
- });
- store.load();
- var data = [
- ['boy', 0],
- ['girl', 1]
- ];
- var store = new Ext.data.Store({
- proxy: new Ext.data.MemoryProxy(data),
- reader: new Ext.data.ArrayReader({}, PersonRecord)
- });
- store.load();
- var store = new Ext.data.Store({
- proxy: new Ext.data.MemoryProxy(data),
- reader: new Ext.data.ArrayReader({}, PersonRecord),
- sortInfo: {field: 'name', direction: 'DESC'}
- });
- var store = new Ext.data.Store({
- proxy: new Ext.data.MemoryProxy(data),
- reader: new Ext.data.ArrayReader({}, PersonRecord),
- sortInfo: {field: 'name', direction: 'DESC'}
- });
- store.getAt(0).get('name')
- store.getAt(0).get('name')
- for (var i = 0; i < store.getCount(); i++) {
- var record = store.getAt(i);
- alert(record.get('name'));
- }
- for (var i = 0; i < store.getCount(); i++) {
- var record = store.getAt(i);
- alert(record.get('name'));
- }
- store.each(function(record) {
- alert(record.get('name'));
- });
- store.each(function(record) {
- alert(record.get('name'));
- });
- var records = store.getRange(0, 1);
- for (var i = 0; i < records.length; i++) {
- var record = records[i];
- alert(record.get('name'));
- }
- var records = store.getRange(0, 1);
- for (var i = 0; i < records.length; i++) {
- var record = records[i];
- alert(record.get('name'));
- }
- store.getById(1001).get('name')
- store.getById(1001).get('name')
- find( String property, String/RegExp value, [Number startIndex], [Boolean anyMatch],[Boolean caseSensitive] )
- find( String property, String/RegExp value, [Number startIndex], [Boolean anyMatch],[Boolean caseSensitive] )
- var index = store.find('name','g');
- alert(store.getAt(index).get('name'));
- var index = store.find('name','g');
- alert(store.getAt(index).get('name'));
- findBy( Function fn, [Object scope], [Number startIndex] ) : Number
- findBy( Function fn, [Object scope], [Number startIndex] ) : Number
- index = store.findBy(function(record, id) {
- return record.get('name') == 'girl' && record.get('sex') == 1;
- });
- alert(store.getAt(index).get('name'));
- index = store.findBy(function(record, id) {
- return record.get('name') == 'girl' && record.get('sex') == 1;
- });
- alert(store.getAt(index).get('name'));
- alert(store.query('name', 'boy'));
- alert(store.queryBy(function(record) {
- return record.get('name') == 'girl' && record.get('sex') == 1;
- }));
- alert(store.query('name', 'boy'));
- alert(store.queryBy(function(record) {
- return record.get('name') == 'girl' && record.get('sex') == 1;
- }));
- store.add(new PersonRecord({
- name: 'other',
- sex: 0
- }));
- store.add(new PersonRecord({
- name: 'other',
- sex: 0
- }));
- store.add([new PersonRecord({
- name: 'other1',
- sex: 0
- }), new PersonRecord({
- name: 'other2',
- sex: 0
- })]);
- store.add([new PersonRecord({
- name: 'other1',
- sex: 0
- }), new PersonRecord({
- name: 'other2',
- sex: 0
- })]);
- store.addSorted(new PersonRecord({
- name: 'lili',
- sex: 1
- }));
- store.addSorted(new PersonRecord({
- name: 'lili',
- sex: 1
- }));
- store.insert(3, new PersonRecord({
- name: 'other',
- sex: 0
- }));
- store.insert(3, [new PersonRecord({
- name: 'other1',
- sex: 0
- }), new PersonRecord({
- name: 'other2',
- sex: 0
- })]);
- store.insert(3, new PersonRecord({
- name: 'other',
- sex: 0
- }));
- store.insert(3, [new PersonRecord({
- name: 'other1',
- sex: 0
- }), new PersonRecord({
- name: 'other2',
- sex: 0
- })]);
- store.remove(store.getAt(0));
- store.removeAll();
- store.remove(store.getAt(0));
- store.removeAll();
- store.getAt(0).set('name', 'xxxx');
- store.getAt(0).set('name', 'xxxx');
- store.load({
- params: {start:0,limit:20},
- callback: function(records, options, success){
- Ext.Msg.alert('info', '加载完毕');
- },
- scope: store,
- add: true
- });
- store.load({
- params: {start:0,limit:20},
- callback: function(records, options, success){
- Ext.Msg.alert('info', '加载完毕');
- },
- scope: store,
- add: true
- });
- store.baseParams.start = 0;
- store.baseParams.limit = 20;
- store.baseParams.start = 0;
- store.baseParams.limit = 20;
- filter( String field, String/RegExp value, [Boolean anyMatch], [Boolean caseSensitive] ) : void
- filter( String field, String/RegExp value, [Boolean anyMatch], [Boolean caseSensitive] ) : void
- store.filter('name', 'boy');
- store.filter('name', 'boy');
- store.filterBy(function(record) {
- return record.get('name') == 'girl' && record.get('sex') == 1;
- });
- store.filterBy(function(record) {
- return record.get('name') == 'girl' && record.get('sex') == 1;
- });
- store.clearFilter();
- store.clearFilter();
- collect( String dataIndex, [Boolean allowNull], [Boolean bypassFilter] ) : Array
- collect( String dataIndex, [Boolean allowNull], [Boolean bypassFilter] ) : Array
- alert(store.collect('name'));
- alert(store.collect('name'));
- alert(store.getTotalCount());
- alert(store.getTotalCount());
- alert(store.indexOf(store.getAt(1)));
- alert(store.indexOfId(1001));
- alert(store.indexOf(store.getAt(1)));
- alert(store.indexOfId(1001));
- store.loadData(data, true);
- store.loadData(data, true);
- alert(store.sum('sex'));
- alert(store.sum('sex'));
表 store提供的事件
事件名 | 参 数 |
add | ( Store this, Ext.data.Record[] records, Number index ) |
beforelaod | ( 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 ) |
语言
zh>en
Yahoo
C
E
error
![自动检测语言和翻译!](https://i-blog.csdnimg.cn/blog_migrate/4dd3435448dade68273e86853488ec0e.png)
Ext.data.Store