bjnelson62
26 Sep 2012, 1:34 PM
I am new to ExtJs, but making progress.
I'm writing a client webapp that talks to a server, which returns data that is hierarchical in nature. Hence, I've chosen a TreePanel to represent this data.
As I learned in a previous post, the root nodes of my tree are static, but the children below come from the server. This is working, up to a point.
Now I've reached the point where the model I was using before for the data is insufficient, as the server is returning a response that doesn't map to this model. Here's an example of the JSON returned by the server:
{
"nodes": [
{
"host-names": [
"machine1"
],
"ip-addresses": [
"192.168.1.33",
"127.0.0.1",
],
"links": [
{
"rel": "self",
"href": "https://localhost:8443/product1/v1/nodes/34/ (https://localhost:8443/vfabric/v1/nodes/34/)",
"type": "application/json; charset=utf-8"
}
]
},
{
"host-names": [
"machine2"
],
"ip-addresses": [
"192.168.1.54",
"127.0.0.1"
],
"links": [
{
"rel": "self",
"href": "https://localhost:8443/product1/v1/nodes/27/ (https://localhost:8443/vfabric/v1/nodes/27/)",
"type": "application/json; charset=utf-8"
}
]
}
],
"links": [
{
"rel": "self",
"href": "https://localhost:8443/product1/v1/nodes/ (https://localhost:8443/vfabric/v1/nodes/)",
"type": "application/json; charset=utf-8"
},
{
"rel": "security",
"href": "https://localhost:8443/product1/v1/security/2/ (https://localhost:8443/vfabric/v1/security/2/)",
"type": "application/json; charset=utf-8"
}
]
}
Here are the two classes I've defined to try to model this:
Ext.define('MyApp.model.NodesModel', {
extend: 'Ext.data.Model',
requires: [
'MyApp.model.LinksModel'
],
// The fields 'host-names' and 'ip-addresses' are both arrays.
fields: [
{name: 'text', mapping: 'host-names', type: 'auto'},
{name: 'id', mapping: 'ip-addresses', type: 'auto'}
],
hasMany: {
model: 'LinksModel', name: 'links', getterName: 'getLinks'
},
proxy: {
type: 'ajax',
noCache: false,
url: 'https://localhost:8443/',
directionparam: undefined,
extraParams: undefined,
filterParam: undefined,
groupParam: undefined,
limitParam: undefined,
pageParam: undefined,
sortParam: undefined,
startParam: undefined,
reader: {
type: 'json',
root: 'nodes'
}
}
});
Ext.define('MyApp.model.LinksModel', {
extend: 'Ext.data.Model',
fields: [
{
name: 'text',
mapping: 'rel'
},
{
name: 'id',
mapping: 'href'
},
{
name: 'type'
}
],
belongsTo: 'NodesModel',
proxy: {
type: 'ajax',
noCache: false,
url: 'https://localhost:8443/',
directionparam: undefined,
extraParams: undefined,
filterParam: undefined,
groupParam: undefined,
limitParam: undefined,
pageParam: undefined,
sortParam: undefined,
startParam: undefined,
reader: {
type: 'json',
root: 'links'
}
}
});
The LinksModel I know works, because the first two layers of the tree use it and the tree is working fine there. I've defined my TreeStore to use the LinksModel by default.
It may be the problem lies with how I'm using these models, and not the model definitions, but I figured to start with the basics first. [Aside: I'm listening to the 'beforeitemexpand' event in the tree, and swapping in the NodesModel into the TreeStore in that function when appropriate.]
Alternatively, how could I debug this to see how the framework is looking at the returned JSON and parsing it (I can see in the debugger that the expected JSON *is* being returned)?
Thank you,
Brian
I'm writing a client webapp that talks to a server, which returns data that is hierarchical in nature. Hence, I've chosen a TreePanel to represent this data.
As I learned in a previous post, the root nodes of my tree are static, but the children below come from the server. This is working, up to a point.
Now I've reached the point where the model I was using before for the data is insufficient, as the server is returning a response that doesn't map to this model. Here's an example of the JSON returned by the server:
{
"nodes": [
{
"host-names": [
"machine1"
],
"ip-addresses": [
"192.168.1.33",
"127.0.0.1",
],
"links": [
{
"rel": "self",
"href": "https://localhost:8443/product1/v1/nodes/34/ (https://localhost:8443/vfabric/v1/nodes/34/)",
"type": "application/json; charset=utf-8"
}
]
},
{
"host-names": [
"machine2"
],
"ip-addresses": [
"192.168.1.54",
"127.0.0.1"
],
"links": [
{
"rel": "self",
"href": "https://localhost:8443/product1/v1/nodes/27/ (https://localhost:8443/vfabric/v1/nodes/27/)",
"type": "application/json; charset=utf-8"
}
]
}
],
"links": [
{
"rel": "self",
"href": "https://localhost:8443/product1/v1/nodes/ (https://localhost:8443/vfabric/v1/nodes/)",
"type": "application/json; charset=utf-8"
},
{
"rel": "security",
"href": "https://localhost:8443/product1/v1/security/2/ (https://localhost:8443/vfabric/v1/security/2/)",
"type": "application/json; charset=utf-8"
}
]
}
Here are the two classes I've defined to try to model this:
Ext.define('MyApp.model.NodesModel', {
extend: 'Ext.data.Model',
requires: [
'MyApp.model.LinksModel'
],
// The fields 'host-names' and 'ip-addresses' are both arrays.
fields: [
{name: 'text', mapping: 'host-names', type: 'auto'},
{name: 'id', mapping: 'ip-addresses', type: 'auto'}
],
hasMany: {
model: 'LinksModel', name: 'links', getterName: 'getLinks'
},
proxy: {
type: 'ajax',
noCache: false,
url: 'https://localhost:8443/',
directionparam: undefined,
extraParams: undefined,
filterParam: undefined,
groupParam: undefined,
limitParam: undefined,
pageParam: undefined,
sortParam: undefined,
startParam: undefined,
reader: {
type: 'json',
root: 'nodes'
}
}
});
Ext.define('MyApp.model.LinksModel', {
extend: 'Ext.data.Model',
fields: [
{
name: 'text',
mapping: 'rel'
},
{
name: 'id',
mapping: 'href'
},
{
name: 'type'
}
],
belongsTo: 'NodesModel',
proxy: {
type: 'ajax',
noCache: false,
url: 'https://localhost:8443/',
directionparam: undefined,
extraParams: undefined,
filterParam: undefined,
groupParam: undefined,
limitParam: undefined,
pageParam: undefined,
sortParam: undefined,
startParam: undefined,
reader: {
type: 'json',
root: 'links'
}
}
});
The LinksModel I know works, because the first two layers of the tree use it and the tree is working fine there. I've defined my TreeStore to use the LinksModel by default.
It may be the problem lies with how I'm using these models, and not the model definitions, but I figured to start with the basics first. [Aside: I'm listening to the 'beforeitemexpand' event in the tree, and swapping in the NodesModel into the TreeStore in that function when appropriate.]
Alternatively, how could I debug this to see how the framework is looking at the returned JSON and parsing it (I can see in the debugger that the expected JSON *is* being returned)?
Thank you,
Brian