ExtJs4如何在创建时将模型分配给存储?
我正在定义一个存储,我想在创建时为它动态分配一个模型。因此,如果我创建了我的ExtJs4如何在创建时将模型分配给存储?,extjs,model,extjs4,Extjs,Model,Extjs4,我正在定义一个存储,我想在创建时为它动态分配一个模型。因此,如果我创建了我的DropDownStore,但没有传递模型配置,它需要依赖于默认模型(DropDownModel) 这是我的DropDownModel+DropDownStore: Ext.define('DropDownModel', { extend: 'Ext.data.Model', fields: [ { name: 'Id', type: 'int' }, { name: 'N
DropDownStore
,但没有传递模型配置,它需要依赖于默认模型(DropDownModel)
这是我的DropDownModel
+DropDownStore
:
Ext.define('DropDownModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'Id', type: 'int' },
{ name: 'Name', type: 'string' }
]
});
Ext.define('DropDownStore', {
extend: Ext.data.Store,
proxy: {
type: 'ajax',
actionMethods: { read: 'POST' },
reader: {
type: 'json',
root: 'data'
}
},
constructor: function(config) {
var me = this;
if (config.listUrl) {
me.proxy.url = config.listUrl;
}
me.model = (config.model) ? config.model : 'DropDownModel'; //This line creates some weird behaviour
me.callParent();
//If the URL is present, load() the store.
if (me.proxy.url) {
me.load();
}
}
});
这是使用动态模型创建的下拉存储
:
Ext.define('RelationModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'Id', type: 'int' },
{ name: 'RelationName', type: 'string' },
{ name: 'RelationOppositeName', type: 'string' }
]
});
...//a random combobox
store: Ext.create('DropDownStore', {
listUrl: 'someprivateurl',
model: 'RelationModel'
})
...
当我将构造函数中的行编辑为
me.model=(config.model)?config.model:未定义
对于动态模型,它的工作方式与预期的一样,但对于默认模型则不再如此
如果我听其自然
me.model=(config.model)?config.model:'DropDownModel'代码>
它适用于默认模型,而不适用于动态模型
如何在创建时将模型分配给商店?
constructor: function(config) {
var me = this;
if (config.listUrl) {
me.proxy.url = config.listUrl;
}
me.callParent();
if (config.extraFields) {
me.model.setFields(config.extraFields);
}
//If the URL is present, load() the store.
if (me.proxy.url) {
me.load();
}
}
store: Ext.create('DropDownStore', {
listUrl: 'someprivateurl',
extraFields: [
{ name: 'Id', type: 'int' },
{ name: 'RelationName', type: 'string' },
{ name: 'RelationOppositeName', type: 'string' }
]
}),