var criterions = {
subconds:{
tree:[
// LAST HEARED
{condID:1, strrep:'Last heared'
subconds:{
tree:[
{condID:5,strrep:'yesterday'}
,{condID:6,strrep:'last week'}
,{condID:7,strrep:'last month'}
,{condID:8,strrep:'last year'}
]
}
}
// MUSIC
,
{condID:17, strrep:'Music',
subconds:{
tree:[
{condID:18,strrep:'Type',
subconds:{
tree:[
{condID:19, strrep:'All'}
,{condID:20, strrep:'Image'}
,{condID:21, strrep:'Movie'}
]
}
}
]
}
}
]
}
}
Ich have this kind of data structure.
I'd need a method that would give me the specific node and subtree
by which the nodes property condID equals to argument searchCondID.
function scantree(searchTree,searchCondID){
var subconditions = searchTree.subconds;
if (subconditions == null){
return;
}
var subconditions_tree = searchTree.subconds.tree;
if (subconditions_tree == null){
return;
}
var i=0;
for (i=0; i<subconditions_tree.length; i++) {
if (subconditions_tree[i].condID == searchCondID){
return subconditions_tree[i];
}
arguments.callee(subconditions_tree[i],searchCondID);
}
}
I mean like function
scantree(criterions, 21);
that would tell me it is a 'Movie'.
The code of mine is too simplistic and doesnt work right.
I have probably wrong exit conditions.
It is available as a quick test& tryout at:
http://marekmand.kuubik.ee/test/recursion.htm