PDA

View Full Version : Recursive copy of tree node issue



wdunn
29 Jun 2012, 11:45 AM
I have a treestore loaded. I want to loop through each immediate child node ( depth level 1). If the child node matches the selection criteria then I want to copy the node and all its children and add them to a new store.


onTreestoreLoad: function(treestore, node, records, successful, options) {
var seq = 1;

for(seq; seq <= treestore.getProxy().reader.jsonData.count; seq++){
var store = Ext.create('Ext.data.TreeStore', {
model: 'MyApp.model.compTree',
storeId: 'compTreeStore' + seq

});
var root = store.setRootNode();

node.eachChild(function(node){
console.log(node);
if (node.data.sequence === seq) {
root.appendChild(node.copy(null, true));
}
});
}
}

The issue it that it sets all the child node id's to MyApp.model.compTree-true and the internal id to "true".

Any help or a simple use case of copying a tree node recursively and applying to another store would be appreciated.

sword-it
29 Jun 2012, 10:41 PM
Hi!

on your selection criteria, you have to create a custom function to copy nodes from one tree to another and then simply get second tree store.

as an example:--




function copyOldTreeNode(node) {
var newTree = new Ext.tree.AsyncTreeNode(node.attributes);
Ext.each(node.childNodes, function(child) {
newTree .appendChild(cloneNode(child));
});
return newTree ;
}