ext中ArrayStore,JsonStore,XmlStore的用法
1.Store的用法
var _store = new Ext.data.Store();
var _record = new Ext.data.Record(["name","sex"]);
var _recordClone = new Ext.data.Record(["name","sex"]);
_record.set('name','张翔');
_record.set('sex','男');
_store.add(_record);
_recordClone.set('name','李慧敏');
_recordClone.set('sex','女');
_store.add(_recordClone);
//alert(_store.getCount());
//alert(_store.getAt(1).get('sex'));
2.ArrayStore的用法
var _store = new Ext.data.ArrayStore({
data:[{name:'张翔',sex:'男'},{name:'李慧敏',sex:'女'}],
fields:[{name:'name',mapping:'name'},{name:'sex',mapping:'sex'}]
});
alert(_store.getAt(1).get('sex'));
3.JsonStore的用法(和ArrayStore差不多,2.0版本之前 ArrayStore是JsonStore的子类)
var _store = new Ext.data.JsonStore({
data:[{name:'张翔',sex:'男'},{name:'李慧敏',sex:'女'}],
fields:[{name:'name',mapping:'name'},{name:'sex',mapping:'sex'}]
});
alert(_store.getAt(1).get('sex'));
4.XmlStore的用法
var _emp = Ext.data.Record.create([{name:'name',mapping:'name'},{name:'sex',mapping:'sex'}]);
var _store = new Ext.data.XmlStore({
url:'/store/xmlStore.xml',
reader:new Ext.data.XmlReader({
totalRecords:'xml',
record:'emp',
id:'id'
},_emp)
});
_store.load();
alert(_store.getCount());
alert(_store.getAt(1).get('sex'));