Store类举例

本文介绍如何在ExtJS中使用localstorage作为数据代理,并设置数据排序与分组字符串的生成方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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来给其赋值。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值