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\',{
            name: \'name\',type: \'string\'
        },{
            name: \'format\',{
            name: \'company_id\',{
...
公司模式
Ext.define(\'DnD.model.Company\',{
    extend: \'Ext.data.Model\',associations: [{
        type: \'hasMany\',model: \'Item\',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() {
    }
});
注意,我可以引用模型,存储和视图,而无需使用完整的名称空间。 任何指导将不胜感激。     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)