1. 使用regStore来创建一个store,通过storeMgr给变量otesApp.stores.notesStore赋值:
Ext.regStore('NotesStore',{
model:'NoteModel',
sorters:[{
property: 'date',
direction: 'DESC'
}],//used only for read data
proxy:{
type: 'localstorage',
id: 'notes-app-stores'
},// The localStorage API puts all data into a single shared namespace, so by setting an id we enable LocalStorageProxy to manage the saved notes data.
getGroupString: function(record){
//console.log('record data: ' + record.data.date);
if(record && record.data.date){//TODO console.log('data.date:' + record.data.date);
return record.get('date').toDateString();// toDateString() shows only date without timing, but found only in ST 2.0 Date class
}else{
return '';
}
}
});
NotesApp.stores.notesStore = Ext.StoreMgr.get('NotesStore');
proxy的type为localstorage是使用游览器当地的存储资源,以id来识别其他数据,提供notes数据。 sorters是用来排列记录,以property指定的字段名来排列,要实现排列还需要getGroupString函数,其参数record对应每条记录,使用record.get('字段名') 或者 record.data.字段名 获取该字段名的值。toDateString() 返回日期,不返回时间。变量NotesApp.stores.notesStore 在创建List时被用到,所以这里必须用StoreMgr来给其赋值。