3

我在设置与跨不同模型重用的嵌套引用的关联时遇到问题。

怎么能做到这一点?

地址模型

    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**

4

1 回答 1

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',    
        }]
    });
于 2014-08-12T02:02:01.693 回答