Ext的數(shù)據(jù)存儲器為:Ext.data.Store
ExtJS中有一個名為Record的類,表格等控件中使用的數(shù)據(jù)是存放在Record對象中,一個Record可以理解為關(guān)系數(shù)據(jù)表中的一行,也可以稱為記錄。Record對象中即包含了記錄(行中各列)的定義信息(也就是該記錄包含哪些字段,每一個字段的數(shù)據(jù)類型等),同時又包含了記錄具體的數(shù)據(jù)信息(也就是各個字段的值)。一個比較正規(guī)的創(chuàng)建store的代碼如下:
var MyRecord = Ext.data.Record.create([
{name: 'title'},
{name: 'username', mapping: 'author'},
{name: 'loginTimes', type: 'int'},
{name: 'lastLoginTime', mapping: 'loginTime', type: 'date'}
]);
var dataProxy=new Ext.data.HttpProxy({url:"login.do"});
var theReader=new Ext.data.JsonReader({
totalProperty: "results",
root: "rows",
id: "id"
},MyRecord
);
var store=new Ext.data.Store({
proxy:dataProxy,
reader:theReader
});
store.load();
store在創(chuàng)建的時候會自動使用HttpProxy來加載參數(shù),并且使用post方式來提交請求,因此上面的代碼可簡化為:
var MyRecord = Ext.data.Record.create([
{name: 'title'},
{name: 'username', mapping: 'author'},
{name: 'loginTimes', type: 'int'},
{name: 'lastLoginTime', mapping: 'loginTime', type: 'date'}
]);
var theReader=new Ext.data.JsonReader({
totalProperty: "results",
root: "rows",
id: "id"
},MyRecord
);
var store=new Ext.data.Store({
url:'login.do',
reader:theReader
});
store.load();
在Store類的基礎(chǔ)上提供了SimpleStore、JSonStore、GroupingStore等,因此上面的JsonReader可以省略:
var store = new Ext.data.JsonStore({
url:'contact.do',
root:'data',
totalProperty:'totalCount',
fields:[{name: 'vid', mapping: 'id'},
{name: 'name', mapping: 'name'},
{name: 'vmethod', mapping: 'vmethod'}]
});