dave_e
28 Nov 2011, 9:59 AM
Hi,
I'm trying to load some existing data which is structured as a tree, display it in a TreePanel and be able to edit it's content and re-save it again.
The data is available over HTTP at urls like :
http://example.com/data/nodes - returns a list of all nodes
http://example.com/data/nodes/1 returns node with id=1
The response from http://example.com/data/nodes looks something like this, and the response from http://example.com/data/nodes/1 is identical except that only a single node value will be returned.
{
"response": [{
"id": 1,
"name": "node-name",
"values": "some data here"
"parent": null,
"children": [2,3]
}, {
"id": 2,
"name": "node-name",
"values": "some data here"
"parent": 1,
"children": []
}, {
"id": 3,
"name": "node-name",
"values": "some data here"
"parent": 1,
"children": []
}]
}
So far, I've found it impossible to set up a TreeStore, Model and Proxy that can load this data and make it available as a hierarchical data structure. Is this possible?
I have managed to load the data if I modify the response to return the full hierarchy e.g. http://example.com/data/nodes/1 will return:
{
"response": [{
"id": 1,
"name": "node-name",
"values": "some data here"
"parent": null,
"children": [{
"id": 2,
"name": "node-name",
"values": "some data here"
"parent": 1,
"children": []
},{
"id": 3,
"name": "node-name",
"values": "some data here"
"parent": 1,
"children": []
}]
}]
}
However, that has other issues. For example, if I edit node 3 then the values stored in the records in the childNodes property is updated, but (presumably) because this is a single Model the data that is sent back to the server is in from the data property which hasn't been updated.
This seems like it would be a fairly common use-case (don't everybody's problems) so I'm hoping there is 'right' way to handle this.
Thanks,
Dave
I'm trying to load some existing data which is structured as a tree, display it in a TreePanel and be able to edit it's content and re-save it again.
The data is available over HTTP at urls like :
http://example.com/data/nodes - returns a list of all nodes
http://example.com/data/nodes/1 returns node with id=1
The response from http://example.com/data/nodes looks something like this, and the response from http://example.com/data/nodes/1 is identical except that only a single node value will be returned.
{
"response": [{
"id": 1,
"name": "node-name",
"values": "some data here"
"parent": null,
"children": [2,3]
}, {
"id": 2,
"name": "node-name",
"values": "some data here"
"parent": 1,
"children": []
}, {
"id": 3,
"name": "node-name",
"values": "some data here"
"parent": 1,
"children": []
}]
}
So far, I've found it impossible to set up a TreeStore, Model and Proxy that can load this data and make it available as a hierarchical data structure. Is this possible?
I have managed to load the data if I modify the response to return the full hierarchy e.g. http://example.com/data/nodes/1 will return:
{
"response": [{
"id": 1,
"name": "node-name",
"values": "some data here"
"parent": null,
"children": [{
"id": 2,
"name": "node-name",
"values": "some data here"
"parent": 1,
"children": []
},{
"id": 3,
"name": "node-name",
"values": "some data here"
"parent": 1,
"children": []
}]
}]
}
However, that has other issues. For example, if I edit node 3 then the values stored in the records in the childNodes property is updated, but (presumably) because this is a single Model the data that is sent back to the server is in from the data property which hasn't been updated.
This seems like it would be a fairly common use-case (don't everybody's problems) so I'm hoping there is 'right' way to handle this.
Thanks,
Dave