PDA

View Full Version : Unable to populate associated Models from a JSON Response



ypandey
7 Aug 2012, 2:22 AM
We are having a Parent Model called AntiSpoofingModel and a associated child Model called CIDRModel.

We are unable to populate the Child Model / Child Store having complete JSON data

Please have a look at the code:




JSON Data :

{
"data":[
{
"name":"1A-1B",
"outboundSpoofing":true,
"cidrList":[
{
"Interface":"1A-1B",
"AdminDomain":"/My Company",
"CIDRAddress":"192.168.215.0/24"
}
],
"inboundSpoofing":true
}
],
"success":true
}

Parent model :

Ext.define('ANTISPOOFING.model.AntiSpoofingModel', {
extend: 'Ext.data.Model',
fields: [
{
name: 'name',
type: 'string'
},
{
name: 'inboundSpoofing',
type: 'boolean'
},
{
name: 'outboundSpoofing',
type: 'boolean'
}
],


hasMany: {
model: 'CIDRModel',
name: 'cidrList'
}
});

Child Model :

Ext.define('ANTISPOOFING.model.CIDRModel', {
extend: 'Ext.data.Model',
fields: [
{
name: 'CIDRAddress',
type: 'string'
},
{
name: 'AdminDomain',
type: 'string'
},
{
name: 'Interface',
type: 'string'
}
],


associations: [
{
type: 'belongsTo',
model: 'AntiSpoofingModel',
name: 'antiSpoofingModel'
}
]


});

Parent Store :

Ext.define("ANTISPOOFING.store.AntiSpoofingStore", {
extend: 'Ext.data.Store',
model:'ANTISPOOFING.model.AntiSpoofingModel',
proxy: {type: 'ajax',
url:'/strutsabc/action/AntiSpoofingAction?userAction=getPortIPSpoofingList',
reader: new Ext.data.JsonReader({
root: 'data'
}
},
autoLoad: true
});



child store :

Ext.define("ANTISPOOFING.store.CIDRStore", {
extend: 'Ext.data.Store',
model:'ANTISPOOFING.model.CIDRModel'
});

access the controller shows undefined

controller code :
var cidrObj = antiSpoofingStore.getAt(0).cidrList();

vietits
7 Aug 2012, 11:32 PM
Try to use full class name for models when configuring model of associations:


Ext.define('ANTISPOOFING.model.AntiSpoofingModel', {
extend: 'Ext.data.Model',
fields: [
{
name: 'name',
type: 'string'
},
{
name: 'inboundSpoofing',
type: 'boolean'
},
{
name: 'outboundSpoofing',
type: 'boolean'
}
],


hasMany: {
model: 'ANTISPOOFING.model.CIDRModel', // use full class name instead of short name
name: 'cidrList'
}
});