PDA

View Full Version : Dynamically change Proxy Reader root



brunofin
20 Jun 2014, 10:10 AM
I have a TreePanel which will have a maximum of 3 levels. First level is the tree's root, which will use a TreeStore to retrieve its children. These children will never be leaves, and they can use the same store of the root level to retrieve its children, which will be the final level of the tree and will always be leaves. These leaves can be retrieved by the same store, but in the JSON they have a different root (and URL, but that's a problem I already solved) than the tree's root, which needs to be changed after the second level is loaded.

I am doing it like this in the TreeStore:


...
listeners: {
beforeload: function(store, operation, eOpts) {
node = operation.node;

if (node.internalId !== 'root' && !node.data.leaf) {
node.store.proxy.url = 'http://localhost:8000/cameras/' + node.getId() + '/';
node.store.proxy.reader.root = 'cameras'; // <= this actually changes the property, but still seems to not work
}
}
}
...


It seems to not work to just change the property and I suspect I must force the store to be reloaded somehow, but I don't know how. Can I have some directions, please?

glopes
20 Jun 2014, 8:43 PM
I could be wrong but you don't change the root of a reader after it's instance has been created.

Try doing this way:



listeners: {
beforeload: function(store, operation, eOpts) {
node = operation.node;

if (node.internalId !== 'root' && !node.data.leaf) {
store.getProxy().url = 'http://localhost:8000/cameras/' + node.getId() + '/';
store.getProxy().setReader({
type : 'json',
root : 'cameras'
});
}
}
}

brunofin
25 Jun 2014, 5:19 AM
Yes! setReader() worked perfectly! Thanks!