Board Logo

search function
naqvia - 5/15/2007 at 04:30 PM

Hi,

I am trying to implement this code that was found earlier-
[code]function setTree (s_caption) {
var o_tree = trees[0],
o_item;
for (var i = 0; i < o_tree.a_index[i].length; i++)
if (o_tree.a_index[i].a_config == s_caption) { // that's where you make the change
o_item = o_tree.a_index[i];
break;
}
if (!o_item)
return alert('item ' + s_caption + ' not found');

// following code opens the parents and selects found item
var n_id = o_item.n_id,
n_depth = o_item.n_depth,
a_index = o_item.o_root.a_index,
a_parents = [o_item];

while (n_depth) {
if (a_index[n_id].n_depth < n_depth) {
a_parents[a_parents.length] = a_index[n_id];
n_depth--;
}
n_id--;
}

for (var i = a_parents.length - 1; i >= 0; i--)
// check if node or root
if (a_parents.a_children) {
a_parents.open();
}
o_item.select();
}[/code]

However when i call the function like this:
new tree (TREE_ITEMS, TREE_TPL);
setTree("At3g59420");

It says 'not found'.. and this is the case for all of the leaf, and parent nodes. What is happening? It is going through the function because its saying not found.. but not matching.. i tried diff. combos too.

ps: all index terms have an "i" and a "[ ]".. but its not showing.


tigra - 5/15/2007 at 05:30 PM

you should disable BBCode in your posting to make sure bracket show up properly in the message (did that for your posting).


if (o_tree.a_index[i].a_config == s_caption) { // that's where you make the change

is incorrect. a_config is the array, and can't be compared to string. it should be:

if (o_tree.a_index[i].a_config[0] == s_caption) { // that's where you make the change


naqvia - 5/15/2007 at 05:38 PM

I made that change and it still cannot find... here is the tree: http://methylome.salk.edu/gene_fam3/. Notice the pop-up.


tigra - 5/15/2007 at 07:19 PM

insert test outputs to see what are the values being compared i.e:

for (var i = 0; i < o_tree.a_index[i].length; i++) {
alert(o_tree.a_index[i].a_config[0] + " " + s_caption);
if (o_tree.a_index[i].a_config[0] == s_caption) { // that's where you make the change
o_item = o_tree.a_index[i];
break;
}
}

usual debugging practice


naqvia - 5/15/2007 at 07:35 PM

I have... your example doesnt print anything..! :(


naqvia - 5/15/2007 at 07:44 PM

Okay.. i found the problem. The reason why its not matching is because on the JSON file the "'At3g59420" has font tags, url, and other html tags with it... how can i just match the first 9 characters?


tigra - 5/15/2007 at 07:54 PM

Check out the list of methods of the JavaScript's String object. It has some for substring extraction.


naqvia - 5/15/2007 at 07:59 PM

Ok.. I got it to substring 9 characters... it is compairing thos correct thing, but it is not opening up the parents. I am comparing leaf nodes.. here is my specific code.
[code]function setTree (s_caption) {
var o_tree = trees[0],
o_item;

for (var i = 0; i < o_tree.a_index.length; i++) {
var sub_section = o_tree.a_index[i].a_config[0].substring(0,9);
if (sub_section == s_caption) { // that's where you make the change
o_item = o_tree.a_index[i];
// return alert(sub_section + ' ' + s_caption);
// return alert(o_item + ' ' + s_caption);

break;
}
}


if (!o_item)
return alert('item ' + s_caption + ' not found');

// following code opens the parents and selects found item
var n_id = o_item.n_id,
n_depth = o_item.n_depth,
a_index = o_item.o_root.a_index,
a_parents = [o_item];

while (n_depth) {
if (a_index[n_id].n_depth < n_depth) {
a_parents[a_parents.length] = a_index[n_id];
n_depth--;
}
n_id--;
}

for (var i = a_parents.length - 1; i >= 0; i--)
// check if node or root
if (a_parents.a_children) {
a_parents.open();
}
o_item.select();
}
[/code]

However, when I setTree('Lyases') or match it with one of the parent nodes, it highlights the parent ....


tigra - 5/15/2007 at 10:41 PM

again the index is missing:
if (a_parents.a_children) {
must be
if (a_parents[i].a_children) {
the same with
a_parents.open();

things like that become obvious if you look at the data types and analyze the code. What's the source of this code?
I think I'll have to disable BBCodes there because forum interpreters [i] as italic font tag.


tigra - 5/15/2007 at 10:47 PM

never mind. found it, disabled BBCodes. I wounder if one can escape the BBCode brackets...


naqvia - 5/15/2007 at 11:15 PM

that wasnt the problem.. still nothing opens adding what you told me to.


tigra - 5/15/2007 at 11:44 PM

insert debug output to see what (if any) is being opened/selected.


Softcomplex: http://www.softcomplex.com/
Back to forum: http://www.softcomplex.com/forum/