Support Forum Softcomplex logo
About Us  | Services  | Download  | Order  | Support  | |
| Search | Today's Posts | Stats | Board Rules | Not logged in [ Login | Register ]
go to bottom
Last active: Never

Printable Version | Subscribe | Add to Favourites   Post new thread
Author: Subject: search function
naqvia
Member

Posts: 13
Registered: 4/12/2007
Location: USA
Member Is Offline
posted on 5/15/2007 at 04:30 PM Reply With Quote
search function


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.
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 5/15/2007 at 05:30 PM Reply With Quote

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
View User's Profile View All Posts By User U2U Member
naqvia
Member

Posts: 13
Registered: 4/12/2007
Location: USA
Member Is Offline
posted on 5/15/2007 at 05:38 PM Reply With Quote

I made that change and it still cannot find... here is the tree: http://methylome.salk.edu/gene_fam3/. Notice the pop-up.
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 5/15/2007 at 07:19 PM Reply With Quote

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
View User's Profile View All Posts By User U2U Member
naqvia
Member

Posts: 13
Registered: 4/12/2007
Location: USA
Member Is Offline
posted on 5/15/2007 at 07:35 PM Reply With Quote

I have... your example doesnt print anything..! :(
View User's Profile View All Posts By User U2U Member
naqvia
Member

Posts: 13
Registered: 4/12/2007
Location: USA
Member Is Offline
posted on 5/15/2007 at 07:44 PM Reply With Quote

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?
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 5/15/2007 at 07:54 PM Reply With Quote

Check out the list of methods of the JavaScript's String object. It has some for substring extraction.
View User's Profile View All Posts By User U2U Member
naqvia
Member

Posts: 13
Registered: 4/12/2007
Location: USA
Member Is Offline
posted on 5/15/2007 at 07:59 PM Reply With Quote

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 ....
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 5/15/2007 at 10:41 PM Reply With Quote

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.
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 5/15/2007 at 10:47 PM Reply With Quote

never mind. found it, disabled BBCodes. I wounder if one can escape the BBCode brackets...
View User's Profile View All Posts By User U2U Member
naqvia
Member

Posts: 13
Registered: 4/12/2007
Location: USA
Member Is Offline
posted on 5/15/2007 at 11:15 PM Reply With Quote

that wasnt the problem.. still nothing opens adding what you told me to.
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 5/15/2007 at 11:44 PM Reply With Quote

insert debug output to see what (if any) is being opened/selected.
View User's Profile View All Posts By User U2U Member
Post new thread

Related Links:
Product Page
Product Demonstrations Live Demos:
Frames targeting
Win help style
Free Download Free Download
Free Download Menu Builders
Online Builder
Product Documentation Documentation:
Documenation Page
Support Forum Technical Support
Support Forum
   

Go To Top


Powered by XMB 1.9.1 Nexus
Developed By Aventure Media & The XMB Group © 2002-2004