I know this has been discussed a lot of times, but I just can't get my code working... So I have a PHP script which returns the following JSON.
I want the data to be loaded in a grid like this:
name | status | ztn | dtn | idn
{
"success":true,
"code":0,
"message":"works",
"data":[
{
"name":"connection1",
"status":1,
"locks":[
{
"ztn":"abc",
"dtn":"def",
"idn":"123"
},
{
"ztn":"ghi",
"dtn":"jkl",
"idn":"456"
}
]
},
{
"name":"connection2",
"status":1,
"locks":[
{
"ztn":"mno",
"dtn":"pqr",
"idn":"789"
}
]
}
My store is set up like this:
Ext.define('VPN.store.Connections', {
extend: 'Ext.data.Store',
id: 'connectionStore',
requires: [
'VPN.model.Connection',
'VPN.model.ConnectionLocks'
],
model: "VPN.model.Connection",
autoLoad: true,
proxy: {
type: 'ajax',
url: 'api/router.php',
reader: {
type: 'json',
root: 'data'
}
}
});
My first model looks like this:
Ext.define("VPN.model.Connection", {
extend: 'Ext.data.Model',
id: 'connectionModel',
fields: ['name', 'status'],
hasMany: {
model: 'VPN.model.ConnectionLocks',
name: 'locks'
}
});
and my second model like this:
Ext.define("VPN.model.ConnectionLocks", {
extend: 'Ext.data.Model',
id: 'connectionLocksModel',
fields: ['ztn', 'dtn', 'idn'],
belongsTo: 'VPN.model.Connections'
});
The grid's store is VPN.model.Connections
. name
and status
are displayed correctly, but the lock's ztn
, dtn
and idn
are not shown...
So where's my mistake?