Tree structure conversion. The first version of recursive temporarily not optimized.
Further written talk recursive rules:
1, determining the return condition
2, the condition determining recursive
3, operation data
4, the return value typically includes: top-level nodes
Cause (no return value here is the use of a reference parameter passing mechanisms, directly address operation, while the top-level node that is the first to pass parameters)
buildExtTree1: function (root,treeDatas) {
if (treeDatas && treeDatas.length != 0){
for (var i = 0,len = treeDatas.length;i<len;i++){
if (!treeDatas[i].hasChildren && i==len-1){
var child = new Ext.tree.TreeNode({
text: treeDatas[i].text,
id: treeDatas[i].id,
leaf: treeDatas[i].leaf
});
root.appendChild(child);
return;
} else {
var child = new Ext.tree.TreeNode({
text: treeDatas[i].text,
id: treeDatas[i].id
// leaf: treeDatas[i].leaf
});
root.appendChild(child);
this.buildExtTree1(child,treeDatas[i].children);
}
}
}else {
return;
}
}