我有存储我想从数据库初始化但我找不到Ext.data.Store
的标准init方法。我找到了StoreManager
组件的几个例子,但我认为这不是我想要的。我的应用程序有一个MVC结构,我想保留它,我只想使用我定义的方法初始化我的商店的数据字段。有人可以解释怎么做吗?
答案 0 :(得分:1)
我要么你理解错了,要么你的问题是直截了当的。您使用这样的模型配置商店。就这样。您可能只是选择了符合您需求的提供商(读者/作者)。
// Set up a model to use in our Store
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{name: 'age', type: 'int'},
{name: 'eyeColor', type: 'string'}
]
});
Ext.define('YourMVCNameSpace.data.UserStore', {
extend: 'Ext.data.Store',
constructor: function (config) {
config = Ext.Object.merge({}, config);
var me = this;
// do what you need with the given config object (even deletes) before passing it to the parent contructor
me.callParent([config]);
// use me forth on cause the config object is now fully applied
},
model: 'User',
proxy: {
type: 'ajax',
url: '/users.json',
reader: {
type: 'json',
root: 'users'
}
},
autoLoad: true
});
请注意,读者会期望像这样的Json结果:
{"total": 55, "users":["...modeldata.."]}
并且指的是像
这样的网址http://localhost/YourAppDomain//users.json
将商店作为“用户”放置在控制器商店阵列中,并通过调用getUserStore()
或使用Ext.StoreMgr.lookup('User')直接从Ext.StoreMgr在Controller中检索它;
请注意,按照惯例,Controller(MVC)将覆盖您在商店中设置的任何storeId,并且只使用该名称。