PDA

View Full Version : Json with class name , help to build nested model



afidalgo
14 Aug 2014, 9:03 AM
Hello all, sorry to bother with this but i've been trying and have no success with this.

i have this json


{
"gateways": [
{
"gateway": {
"name": "alexis",
"parameters": [
{
"name": "username",
"value": "alexis"
},
{
"name": "password",
"value": "pepe"
},
{
"name": "proxy",
"value": "10.0.1.3"
},
{
"name": "register",
"value": ""
},
{
"name": "register-transport",
"value": "udp"
},
{
"name": "caller-id-in-from",
"value": "true"
}
]
}
},
{
"gateway": {
"name": "asterlink.com",
"parameters": [
{
"name": "username",
"value": "cluecon"
},
{
"name": "password",
"value": "2007"
},
{
"name": "proxy",
"value": "asterlink.com"
},
{
"name": "register",
"value": "false"
},
{
"name": "register-transport",
"value": "udp"
},
{
"name": "caller-id-in-from",
"value": "true"
}
]
}
},
{
"gateway": {
"name": "DWG2000E1",
"parameters": [
{
"name": "username",
"value": "cys"
},
{
"name": "password",
"value": "cys"
},
{
"name": "proxy",
"value": "10.1.100.180:5060"
},
{
"name": "register",
"value": "false"
},
{
"name": "register-transport",
"value": "udp"
},
{
"name": "caller-id-in-from",
"value": "true"
}
]
}
},
{
"gateway": {
"name": "DWG2000E2",
"parameters": [
{
"name": "username",
"value": "cys"
},
{
"name": "password",
"value": "cys"
},
{
"name": "proxy",
"value": "10.1.100.181:5060"
},
{
"name": "register",
"value": "false"
},
{
"name": "register-transport",
"value": "udp"
},
{
"name": "caller-id-in-from",
"value": "true"
}
]
}
},
{},
{
"gateway": {
"name": "IPO252",
"parameters": [
{
"name": "username",
"value": "cys"
},
{
"name": "password",
"value": "cys"
},
{
"name": "context",
"value": "cachitolasbolas"
},
{
"name": "proxy",
"value": "10.1.100.252:5060"
},
{
"name": "register",
"value": "false"
},
{
"name": "register-transport",
"value": "udp"
},
{
"name": "caller-id-in-from",
"value": "true"
}
]
}
}
],
"success": true
}

and this is what i have as model


Ext.define('sfe.model.Gateway', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string', mapping: 'gateway.name'}
],
hasMany: {model: 'sfe.model.Param', name: 'parameters', mapping: 'gateway.parameters'}
});

Ext.define('sfe.model.Param', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
{name: 'value', type: 'string'}
], belongsTo: 'sfe.model.Gateway'
});



in a grid, im able to see the gateway name, but looking the store with a console.log i can see no "parameters" at all.

any clue will be appreciated.

thanks

skirtle
14 Aug 2014, 4:08 PM
Try associationKey instead of mapping:

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.association.HasMany-cfg-associationKey

You may also benefit from using the record config on your reader:

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.reader.Json-cfg-record

afidalgo
16 Aug 2014, 2:13 PM
thanks a lot