我试图在我的应用程序中集中化EXTJS存储的配置,但是,我似乎无法弄清楚如何做到这一点。我正在使用ExtJS 4.1。
我有一个基础商店,我想保留所有重复的配置资料,然后我的更具体的商店来保留实际的不同。
Ext.define('My.store.Abstract', {
extend: 'Ext.data.Store',
autoload:false,
proxy: {
type: 'ajax',
reader: {
type: 'json',
root: 'data',
totalProperty: 'total',
successProperty: 'success',
messageProperty: 'message'
},
writer: {
type: 'json',
encode: true,
writeAllFields: true,
root: 'data',
allowSingle: false
},
simpleSortMode: true
}
});
然后,我想在各个商店的基础上为商店提供特定的商品-
Ext.define('My.store.Products', {
extend: 'My.store.Abstract',
storeId: 'Products',
model: 'My.model.Product',
proxy: {
api: {
create: '/myurl/create',
read: '/myurl/index',
update: '/myurl/update',
destroy: '/myurl/delete'
}
}
});
我发现的是它根本不表现任何行为。我相信它与代理有关,但是我无法对其进行跟踪。
正确的方法是什么?我不想在我的应用程序的350多个存储中复制相同的配置内容(从我的抽象存储中复制)。到现在为止,这就是我所拥有的,我以为我正在尝试实现一个非常基本的概念..无济于事。
我知道事情无法正常运行,就像pageSize甚至autoLoad一样基本,因为它们根本没有受到尊重。
我玩过构造函数,并调用了父级。
任何帮助将不胜感激。
最佳答案
您不能那样做,因为您希望合并它不会做的对象。
相反,您将需要查看以下内容(未经测试):
Ext.define('Base', {
extend: 'Ext.data.Store',
autoLoad: false,
constructor: function(config) {
// applyIf means only copy if it doesn't exist
Ext.applyIf(config, {
proxy: this.createProxy()
});
this.callParent([config]);
},
createProxy: function() {
return {
reader: {
type: 'json',
root: 'data',
totalProperty: 'total',
successProperty: 'success',
messageProperty: 'message'
},
writer: {
type: 'json',
encode: true,
writeAllFields: true,
root: 'data',
allowSingle: false
},
simpleSortMode: true
}
}
});
Ext.define('Sub', {
extend: 'Base',
createProxy: function(){
var proxy = this.callParent();
proxy.api = {
create: 'create',
update: 'update'
};
return proxy;
}
});
关于extjs - 扩展Ext.data.Store,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13807612/