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"}