sencha2中建立复杂Model

sencha是js框架Ext js基于移动端的开发框架,采用优秀的MVC设计模式。

结构分为Model(模型),Store(存储),View(视图),Controller(控制器)。

下面是一个复杂的Model,即json所对应的对象模型,当中包含对象和数组。


它的Model为:

Ext.define('App.model.ResultModel',{
           extend:'Ext.data.Model',
           config:{
           fields:['cutOffLocalTime','estimatedTransitTimeInDays','originHaulageIndicator',
                   'FNDHaulageIndicator','isSvvdQueryAvailable'],
           associations: [{
               type: 'hasOne',
               model: 'App.model.Carrier',
               name:'carrier'
           },
           {
        	   type: 'hasOne',
               model: 'App.model.Origin',
               name:'origin'
           },
           {
        	   type: 'hasOne',
               model: 'App.model.Destination',
               name:'destination'
           },
           {
        	   type: 'hasOne',
               model: 'App.model.CutOffLocalDate',
               name:'cutOffLocalDate'
           },
           {
        	   type: 'hasOne',
               model: 'App.model.ETAatFNDModel',
               name:'ETAatFND',
               associationKey:'ETAatFND'
           },
           {
        	   type:'hasOne',
        	   model:'App.model.OceanComponent',
        	   name:'oceanComponent'
           }
           ]
           }
});

//result
Ext.define('App.model.Carrier',{
    extend:'Ext.data.Model',
    config:{
    fields:['SCAC','shortName','fullName']
    }
});

Ext.define('App.model.Origin',{
    extend:'Ext.data.Model',
    config:{
    fields:['city','country','UNLOCODE','facilityCode']
    }
});

Ext.define('App.model.Destination',{
    extend:'Ext.data.Model',
    config:{
    fields:['city','country','UNLOCODE','facilityCode']
    }
});

Ext.define('App.model.CutOffLocalDate',{
    extend:'Ext.data.Model',
    config:{
    fields:['year','month','dayOfMonth','hourOfDay','minute','second']
    }
});

Ext.define('App.model.ETAatFNDModel',{
    extend:'Ext.data.Model',
    config:{
    fields:['year','month','dayOfMonth','hourOfDay','minute','second']
    }
});

Ext.define('App.model.OceanComponent',{
    extend:'Ext.data.Model',
    config:{
    hasMany:{model:'App.model.Oceanleg',name:'oceanleg',associationKey:'oceanleg'}
    }
});

//result.oceanComponent
Ext.define('App.model.Oceanleg',{
    extend:'Ext.data.Model',
    config:{
    	fields:['legSequence','serviceCode','vesselCode','vesselName','IntegerernalVoyageNumber','externalVoyageNumber','direction'],
    	associations: [{
            type: 'hasOne',
            model: 'App.model.POL',
            name:'POL',
            associationKey:'POL'
        },
        {
            type: 'hasOne',
            model: 'App.model.POD',
            name:'POD',
            associationKey:'POD'
        }]
    }
});

//result.oceanComponent.oceanleg
Ext.define('App.model.POL',{
    extend:'Ext.data.Model',
    config:{
    fields:['UNLOCODE','portName','callNumber','facilityCode'],
    hasOne:{model:'App.model.ETD',name:'ETD',associationKey:'ETD'}
    }
});

Ext.define('App.model.POD',{
    extend:'Ext.data.Model',
    config:{
    fields:['UNLOCODE','portName','callNumber','facilityCode'],
    hasOne:{model:'App.model.ETA',name:'ETA',associationKey:'ETA'}
    }
});
//result.oceanComponent.oceanleg.POL
Ext.define('App.model.ETD',{
    extend:'Ext.data.Model',
    config:{
    fields:['year','month','dayOfMonth','hourOfDay','minute','second']
    }
});
//result.oceanComponent.oceanleg.POD
Ext.define('App.model.ETA',{
    extend:'Ext.data.Model',
    config:{
    fields:['year','month','dayOfMonth','hourOfDay','minute','second']
    }
});

json字符串为:

{"carrier":{"SCAC":"HDMU",
"shortName":"Hyundai",
"fullName":"Hyundai"},
"origin":{"city":"HONG KONG, CHINA",
"UNLOCODE":"HKHKG"},
"destination":{"city":"SINGAPORE",
"UNLOCODE":"SGSIN"},
"oceanComponent":{"oceanleg":[{"POL":{"UNLOCODE":"HKHKG",
"portName":"HONG KONG, CHINA",
"callNumber":1,
"ETD":{"year":2012,
"month":3,
"dayOfMonth":13,
"hourOfDay":0,
"minute":0,
"second":0}},
"POD":{"UNLOCODE":"SGSIN",
"portName":"SINGAPORE",
"callNumber":2,
"ETA":{"year":2012,
"month":3,
"dayOfMonth":15,
"hourOfDay":0,
"minute":0,
"second":0}},
"serviceCode":"LPC",
"vesselName":"OOCL NORFOLK",
"externalVoyageNumber":"040E"}]},
"ETAatFND":{"year":2012,
"month":3,
"dayOfMonth":15,
"hourOfDay":0,
"minute":0,
"second":0},
"estimatedTransitTimeInDays":1,
"isSvvdQueryAvailable":"1"}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值