I\'m making a TreePanel that looks like this:
At the moment I have it \"mo
Here is my function to convert normal data to treeStore data, you can use that. By that way, you don't need treeStore anymore:
Records: array of record. Text: name of item (get from record) Children: name of children (default is 'children')
dynamicReportsStore.load({
scope: this,
callback: function (records, operation) {
if (operation.isComplete()) {
var tree = this.buildTreeByRecords(records, 'name');
treePanel.getRootNode().removeAll();
treePanel.getRootNode().appendChild(tree);
}
}
});
buildTreeByRecords: function (records, text, children) {
var childs = [],
results = [],
tree = [];
records = Ext.Array.map(records, function (record) {
return {
text: record.get(text) || record.get('id'),
leaf: record.get('leaf'),
expanded: true,
parentId: record.get('parentId'),
id: record.get('id')
};
}, this);
Ext.each(records, function (record) {
if (Ext.isEmpty(childs[record.parentId])) {
childs[record.parentId] = [];
}
childs[record.parentId].push(record);
}, this);
Ext.each(records, function (record) {
if (!Ext.isEmpty(childs[record.id])) {
record[children || 'children'] = childs[record.id];
results.push(record);
}
}, this);
Ext.each(results, function (result) {
if (result.parentId === 0) {
tree.push(result);
}
}, this);
return tree;}