PDA

View Full Version : Problem accessing treestore child nodes



qlc
26 May 2013, 7:22 AM
I am loading a treestore, getting the root node, then trying to iterate over the children. From what I observe, to seems to me that the tree is loaded into the store, I am able to get the root, when I expand the root in Chrome's console I am able to see children, but when I try to access the children from ExtJS they seem to be missing.

Any help would be greatly appreciated. Thank you in advance.


var ts = this.getStore('QaireTreeStore');

console.log("--- ts:");
console.log(ts);

var p = ts.getProxy();

console.log("--- p:");
console.log(p);

p.extraParams = {};

p.setExtraParam('prgmCode','arg1');
p.setExtraParam('qaireCode','arg2');

ts.removeAll();
ts.load();

var rn = ts.getRootNode();

console.log("--- rn:");
console.log(rn);


console.log("--- isRoot");
console.log(rn.isRoot());

rn.eachChild(function(n) {
console.log('-- n:');
console.log(n);
});

console.log("--- firstChild:");
console.log(rn.firstChild);


console.log("--- childNodes:");
console.log(rn.childNodes);

console.log("--- getChildAt 0:");
console.log(rn.getChildAt(0));


I get this output in the console:


--- ts: SrvyController.js:71
constructor {autoLoad: false, model: function, storeId: "QaireTreeStore", proxy: constructor, fields: Array[1]…}
SrvyController.js:72
--- p: SrvyController.js:76
constructor {type: "ajax", api: Object, reader: constructor, model: function, hasListeners: HasListeners…}
SrvyController.js:77
--- rn: SrvyController.js:89
constructor {phantom: false, internalId: "ext-record-1", raw: Object, data: Object, modified: Object…}
childNodes: Array[1] <-- I expanded this in the console to show the data exists
0: constructor
childNodes: Array[9]
data: Object
dirty: false
editing: false
events: Object
firstChild: constructor
hasListeners: HasListeners
id: "IHA.model.QaireModel-48"
internalId: 48
lastChild: constructor
modified: Object
nextSibling: null
parentNode: constructor
phantom: false
previousSibling: null
raw: Object
stores: Array[0]
proto: TemplateClass
length: 1
proto: Array[0]
data: Object
dirty: false
editing: false
events: Object
firstChild: constructor
hasListeners: HasListeners
id: "IHA.model.QaireModel-ext-record-1"
internalId: "ext-record-1"
lastChild: constructor
modified: Object
nextSibling: null
parentNode: null
phantom: false
previousSibling: null
raw: Object
stores: Array[0]
proto: TemplateClass
SrvyController.js:90
--- isRoot SrvyController.js:93
true SrvyController.js:94
--- firstChild: SrvyController.js:101 <-- children not here
null SrvyController.js:102
--- childNodes: SrvyController.js:105 <-- children not here
[] SrvyController.js:106
--- getChildAt 0: SrvyController.js:108 <-- children not here
undefined

Farish
27 May 2013, 12:56 AM
the most likely case is that the treeStore is not loaded. in the console, it might show you the root node with all its children but they are loaded afterwards. what you can try is the following:


ts.on('load', function() {
var rn = ts.getRootNode();

console.log("--- rn:");
console.log(rn);

console.log("--- isRoot");
console.log(rn.isRoot());

rn.eachChild(function(n) {
console.log('-- n:');
console.log(n);
});

console.log("--- firstChild:");
console.log(rn.firstChild);

// and the rest of your code.
});

qlc
27 May 2013, 5:08 AM
That resolved the problem. But, since I'm using MVC, I put this in the controller: this.getSrvyTreeStoreStore().addListener('load',this.processTree, this);