var criterions = {
subconds:{
tree:[
// LAST HEARED
{condID:1, strrep:'Last heared'
subconds:{
tree:[
{condID:5,strre p:'yesterday'}
,{condID:6,strr ep:'last week'}
,{condID:7,strr ep:'last month'}
,{condID:8,strr ep:'last year'}
]
}
}
// MUSIC
,
{condID:17, strrep:'Music',
subconds:{
tree:[
{condID:18,strr ep:'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(search Tree,searchCond ID){
var subconditions = searchTree.subc onds;
if (subconditions == null){
return;
}
var subconditions_t ree = searchTree.subc onds.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_t ree[i];
}
arguments.calle e(subconditions _tree[i],searchCondID);
}
}
I mean like function
scantree(criter ions, 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:
subconds:{
tree:[
// LAST HEARED
{condID:1, strrep:'Last heared'
subconds:{
tree:[
{condID:5,strre p:'yesterday'}
,{condID:6,strr ep:'last week'}
,{condID:7,strr ep:'last month'}
,{condID:8,strr ep:'last year'}
]
}
}
// MUSIC
,
{condID:17, strrep:'Music',
subconds:{
tree:[
{condID:18,strr ep:'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(search Tree,searchCond ID){
var subconditions = searchTree.subc onds;
if (subconditions == null){
return;
}
var subconditions_t ree = searchTree.subc onds.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_t ree[i];
}
arguments.calle e(subconditions _tree[i],searchCondID);
}
}
I mean like function
scantree(criter ions, 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:
Comment