ExtJS4:何时使用完整命名空间VS只是对象名称(模型关联)
||
我的项目模型的一部分:
Ext.define(\'DnD.model.Item\', {
extend: \'Ext.data.Model\',
idProperty:\'item_number\',
associations: [{
type: \'belongsTo\',
model: \'Company\',
primaryKey: \'id\',
foreignKey: \'company_id\',
autoLoad: true
}],
proxy: {
type: \'ajax\',
url: \'data/items.json\',
reader: {
type: \'json\',
root: \'items\',
idProperty:\'id\'
}
},
fields: [{
name: \'id\',
type: \'int\'
},{
name: \'box_number\',
type: \'float\'
}, {
name: \'item_number\',
type: \'float\'
}, {
name: \'name\',
type: \'string\'
},{
name: \'format\',
type: \'int\'
}, {
name: \'company_id\',
type: \'int\'
}, {
...
公司模式
Ext.define(\'DnD.model.Company\', {
extend: \'Ext.data.Model\',
associations: [{
type: \'hasMany\',
model: \'Item\',
primaryKey: \'id\',
foreignKey: \'company_id\',
autoLoad: true
}],
idProperty:\'id\',
fields: [{
name: \'id\',
type: \'int\'
}, {
name: \'name\',
type: \'string\'
}],
proxy: {
type: \'ajax\',
url: \'data/companies.json\',
reader: {
successProperty: true,
type: \'json\',
root: \'companies\',
idProperty:\'id\'
}
}
})
app.js文件
Ext.Loader.setConfig({
enabled: true,
paths: {
Ext: \'extjs/src\',
My: \'app\'
}
});
Ext.application({
name: \'DnD\',
appFolder: \'app\',
autoCreateViewport: false,
controllers: [
\'Collections\',
\'Items\'
],
launch: function() {
this.viewport = Ext.create(\'DnD.view.Viewport\', {});
this.viewport.show();
}
});
问题
使用代码的方式,每当我创建项目模型的新实例并尝试调用myItem.getCompany()
时,控制台都会引发错误,告诉我创建的对象没有这种方法。
现在,如果我将关联更改为说某个项目属于DnD.model.Company
(而不是Company
),则会创建一个getter方法,但它被称为getDnD.model.Company()
(而不是getCompany()
)。
从我所看到的情况来看,除非我提到完整的路径名,否则看来自动加载器无法找到模型。但是,请看一下我的Collection Controller:
Ext.define(\'DnD.controller.Collections\', {
extend: \'Ext.app.Controller\',
models: [
\'Collection\'
],
stores: [
\'Collections\',
],
views:[
\'collection.List\'
],
refs: [{
ref: \'collectionList\',
selector: \'collectionlist\'
}],
init: function() {
}
});
注意,我可以引用模型,存储和视图,而无需使用完整的名称空间。
任何指导将不胜感激。
没有找到相关结果
已邀请:
1 个回复
babsoft