数据包用于加载和保存应用程序中的所有数据。
数据包有许多类,但最重要的类是:
ext.define('studentdatamodel', { extend: 'ext.data.model', fields: [ {name: 'name', mapping : 'name'}, {name: 'age', mapping : 'age'}, {name: 'marks', mapping : 'marks'} ] });
这里的名称应该与我们在视图中声明的dataindex相同,并且映射应该匹配使用store从数据库获取的静态或动态数据。
store的基类是ext.data.store。 它包含本地缓存的数据,该数据将在模型对象的帮助下在视图上呈现。 存储使用代理获取数据,代理具有为服务定义的路径以获取后端数据。
存储数据可以从静态或动态两种方式获取。
对于静态存储,我们将存储在存储中的所有数据如下:
ext.create('ext.data.store', { model: 'studentdatamodel', data: [ { name : "asha", age : "16", marks : "90" }, { name : "vinit", age : "18", marks : "95" }, { name : "anand", age : "20", marks : "68" }, { name : "niharika", age : "21", marks : "86" }, { name : "manali", age : "22", marks : "57" } ]; });
可以使用代理获取动态数据。 我们可以让代理可以从ajax,rest和json获取数据。
代理的基类是ext.data.proxy.proxy。 代理由模型和商店用于处理模型数据的加载和保存。
有两种类型的代理:
客户端代理包括使用html5本地存储的内存和本地存储。
服务器代理使用ajax,json数据和rest服务处理来自远程服务器的数据。
ext.create('ext.data.store', { model: 'studentdatamodel', proxy : { type : 'rest', actionmethods : { read : 'post' // get or post type based on requirement }, url : 'resturlpathorjsonfilepath', // here we have to include the rest url path which fetches data from database or json file path where the data is stored reader: { type : 'json', // the type of data which is fetched is of json type root : 'data' }, } });