Extjs 5.0模型中的嵌套关​​联导致错误= Ext.data.schema.Schema.addEntity():重复的实体名称

时间:2014-08-12 00:52:48

标签: extjs5

我无法设置与不同模型重用的嵌套引用的关联。

怎么做呢?

AddressModel

    Ext.define('POC.model.AddressModel', 
    {
        extend: 'Ext.data.Model',    
        fields: [             
                 { name:'id', type:'string' },
                 { name:'line1', type:'string' },
                 { name:'line2', type:'string' },
                 { name:'city', type:'string' },             
                 { name:'state', type:'string'},
                 { name:'zip', type:'string'}
             ]
    });

申请人模型

    Ext.define('POC.model.ApplicantModel', 
    {
        extend: 'POC.model.Base',
        requires: [
                   "POC.model.field.PhoneNumber",  
                   "POC.model.AddressModel"
               ],
        fields: [             
                 { name:'id', type:'string' },             
                 { name:'applicantName', type:'string'}, 
                 { name:'mailingAddress', reference:'AddressModel'} 
             ]
    });

公司模式

    Ext.define('POC.model.CompanyInfoModel', 
    {
        requires: [
                   "POC.model.field.PhoneNumber",  
                   "POC.model.AddressModel"
               ],
        extend: 'Ext.data.Model',    
        fields: [             
                 { name:'id', type:'string'},
                 { name:'contacttype', type:'string' },
                 { name:'contactname', type:'string' },
                 { name:'primaryphone', type:'phonenumber' },
                 { name:'secphone', type:'phonenumber' },             
                 { name:'primaryemail', type:'string'},
                 { name:'secemail', type:'string'},
                 { name:'address', reference:'AddressModel'}            
             ]     
    });

代理商模型

    Ext.define('POC.model.AgentInfoModel', 
    {
        extend: 'Ext.data.Model',
        requires: [
                   "POC.model.field.PhoneNumber",  
                   "POC.model.AddressModel"
               ],
        fields: [             
                 { name:'id', type:'string'},
                 { name:'agencyname', type:'string' },
                 { name:'contactname', type:'string' },
                 { name:'phone', type:'phonenumber' },             
                 { name:'code', type:'string'},
                 { name:'email', type:'string'},
                 { name:'address', reference:'AddressModel'}
             ]
    });

应用程序模型中的所有内容都在一起

    Ext.define('POC.model.ApplicationInfoModel', 
    {
        requires:['POC.model.AgentInfoModel',
                  'POC.model.CompanyInfoModel',
                  'POC.model.ApplicantModel'
                  ],
        extend: 'POC.model.Base',
        idProperty:'appid',
        fields:[{
                    name:'appid',type:'string'
                },
                {
                    name:'agent',
                    reference:'AgentInfoModel'
                },
                {
                    name:'company',
                    reference:'CompanyInfoModel'
                }           
                ],
        hasMany:[{
            name:'applicants',
            reference:'ApplicantModel'
        }]
    });

来自服务器的关联JSON格式

    {
        "success":true,
        "application" : 
        {
            "appid":"0",
            "company" : 
            {
                "id" : "0",
                "contacttype" : "",
                "contactname" : "",
                "primaryphone" : "",
                "secphone" : "",
                "primaryemail" : "",
                "secemail" : "",
                "address" : {
                    "id":"114444",
                    "line1" : "",
                    "line2" : "",
                    "city" : "",
                    "state" : "",
                    "zip" : ""
                }
            },
            "agent" : {
                "id" : "0",
                "agencyname" : "",
                "contactname" : "",
                "phone" : "",
                "code" : "",
                "email" : "",
                "address" : {
                    "id":"11111",
                    "line1" : "",
                    "line2" : "",
                    "city" : "",
                    "state" : "",
                    "zip" : ""
                }
            },
            "applicants" :
            [{
                    "id" : "0",             
                    "applicantName" : "",
                    "mailingAddress" : 
                    {
                        "id":"1132323",
                        "line1" : "",
                        "line2" : "",
                        "city" : "",
                        "state" : "",
                        "zip" : ""
                    }
                }, {
                    "id" : "1",
                    "applicantName" : "",
                    "mailingAddress" : 
                    {
                        "id":"11323666",
                        "line1" : "",
                        "line2" : "",
                        "city" : "",
                        "state" : "",
                        "zip" : ""
                    }
                }

            ]

        }
    }

我得到的错误......

** W] [Ext.define]指定的重复类名'POC.model.AddressModel',必须是非空字符串Util.js:692

[E] Ext.data.schema.Schema.addEntity():重复的实体名称“AddressModel”:POC.model.AddressModel和POC.model.AddressModel

未捕获错误:重复的实体名称“AddressModel”:POC.model.AddressModel和POC.model.AddressModel **

1 个答案:

答案 0 :(得分:0)

解决了ApplicationInfoModel必须改变的问题,如下所示

Ext.define('POC.model.ApplicationInfoModel', 
    {
        requires:['POC.model.AgentInfoModel',
                  'POC.model.CompanyInfoModel',
              //    'POC.model.ApplicantModel'
                  ],
        extend: 'POC.model.Base',
        idProperty:'appid',
        fields:[{
                    name:'appid',type:'string'
                },
                {
                    name:'agent',
                    reference:'AgentInfoModel'
                },
                {
                    name:'company',
                    reference:'CompanyInfoModel'
                }           
                ],
        hasMany:[{
            name:'applicants',
            model:'POC.model.ApplicantInfoModel',    
        }]
    });