Dynamic 如何基于变量的值动态构造和扩展ExtJS对象?
我有以下代码。我希望根据选择的是url.local还是url.remote,使代理的类型和url属性成为动态的Dynamic 如何基于变量的值动态构造和扩展ExtJS对象?,dynamic,extjs,constructor,Dynamic,Extjs,Constructor,我有以下代码。我希望根据选择的是url.local还是url.remote,使代理的类型和url属性成为动态的 var url = { local: './grid-filtering/sample.json', // static data file remote: '/Customer/Get' }; Ext.require('sbpm.model.Product'); Ext.define('sbpm.store.Customer', { extend: 'Ex
var url = {
local: './grid-filtering/sample.json', // static data file
remote: '/Customer/Get'
};
Ext.require('sbpm.model.Product');
Ext.define('sbpm.store.Customer', {
extend: 'Ext.data.JsonStore',
constructor: function (cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
// store configs
autoDestroy: true,
storeId: 'Customer',
model: 'sbpm.model.Product',
proxy: {
type: 'jsonp',
url: url.local,
reader: {
root: 'data',
totalProperty: 'total'
}
},
remoteSort: false,
sorters: [{
property: 'company',
direction: 'ASC'
}],
pageSize: 50
}), cfg]);
}
});
换句话说,我要做的是指定伪代码:
if (url.local)
{
proxy:{
type: 'jsonp'
url: url.local,
// etc
}
}
else if (url.remote)
{
proxy:{
type: 'rest'
url: url.remote,
// etc
}
}
很抱歉,我不知道应该添加什么样的上下文来进一步解释该场景,或者如果stackoverflow只是使用某种文本/代码比率来衡量,我已经非常简洁地解释了这个场景,如果人们不理解,他们可以问更详细的问题,这会让人很恼火。AbstractStore类有两个方法setProxy/getProxy。您可以使用它们动态切换代理。如果您需要更多的东西,比如在内部有两个不同的代理并在它们之间切换而无需重新创建,那么您可能需要扩展现有的类。Perfect。谢谢你,沙!你刚才查过了吗。我觉得很不舒服;我早该知道的,是的。我只是看了一下来源。ExtJs具有非常好的结构和注释良好的源代码:当有疑问时,请看那里。