PDA

View Full Version : TreeStore loads data when expanding a node - right?



Arg0n
4 Oct 2012, 5:22 AM
I made a Tree Store:



Ext.define('BLA.store.TestplanTreeGrid', {
extend: 'Ext.data.TreeStore',
uses: ['BLA.model.TestplanTreeGrid'],
model: 'BLA.model.TestplanTreeGrid',
storeId: 'testplan-treegrid',
proxy: {
type: 'ajax',
api: {
read: '../service/testplan/fetch',
},
reader: {
type: 'json',
root: 'data'
}
}
});


When I expand a node, the store loads again. If I remove the root: 'data' from the reader, the store doesn't load again when I expand a node. Could someone explain me why the store is doing that? Is this behavior correct? Is it a bug? Is there a way to avoid loading when setting a root config?

HINT: Of course I changed the returned data, when I was removing the root: 'data' config.

scottmartin
6 Oct 2012, 5:35 PM
The default to get tree to load is as follows:



{
"id": 8,
"parent": 5,
"text": "Node-1.2.3",
"leaf": false, // folder
"expanded": false // not expand, waiting for click
}


This will change if:
leaf: true // end point; no call
"children": [] // children assign; done

If you set expanded true and leaf is false, you can expect an extra call to server if there are no children assigned, as it tries to load.

When you remove the root property, I suspect that server is still called, but the response is not handled correctly and hence the store is not populated.

Scott.

scottmartin
6 Oct 2012, 5:39 PM
To illustrate this, the following example will make a server all when you click on: Node-1.2.3



[
{
"id": 2,
"parent": 1,
"text": "Node-1.1",
"leaf": false,
"expanded": true,
"children": [
{
"id": 3,
"parent": 2,
"text": "Node-1.1.1",
"leaf": true,
"expanded": false,
"children": []
},
{
"id": 4,
"parent": 2,
"text": "Node-1.1.2",
"leaf": true,
"expanded": false,
"children": []
}
]
},
{
"id": 5,
"parent": 1,
"text": "Node-1.2",
"leaf": false,
"expanded": true,
"children": [
{
"id": 6,
"parent": 5,
"text": "Node-1.2.1",
"leaf": true,
"expanded": false,
"children": []
},
{
"id": 7,
"parent": 5,
"text": "Node-1.2.2",
"leaf": true,
"expanded": false,
"children": []
},
{
"id": 8,
"parent": 5,
"text": "Node-1.2.3",
"leaf": false,
"expanded": false
}
]
}
]




Ext.onReady(function () {
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 300,
store: {
root: {
text: 'Root',
expanded: true
},
proxy: {
type: 'ajax',
url: 'getsomenodes.json' //getallnodes
}
},
renderTo: Ext.getBody()
});
});


Scott