Board Logo

Tree search & select not functioning
jsuen - 1/14/2007 at 06:28 PM


I'm having some problems in getting the select(n_id) function working with a given node id in a defined tree.

A sample of the search function I'd like to use is as follows - for a unique param, select that indexed row within the tree:
function search(param) {
var found = TREES['MyTree'].find_item(param);


The find_item invocation works as expected, and displays the correct index of the found node in the alert() line. However, it trips up around the select statement, and I get the following JavaScript error in IE each time:

"Object doesn't support this property or method"

Any help would be greatly appreciated, thanks.


tigra - 1/14/2007 at 07:18 PM

you can't call .select() on non-initialized items (those are the items that haven't been displayed at least once after the page loaded). You need to call .open() method on all parents of the item starting from the root level before calling .select(). See the sample in the product documentation for that.

jsuen - 1/15/2007 at 08:16 PM


Thanks for your help, I have slightly modified the sample openItemByCaption() sample in the documentation given, and was just looking to add it further to behave as though the user clicked on a node (and opened the branch) of a certain item.

At present, the sample code will open the branch with the corresponding node found - is it possible to also have the item selected (i.e. link opened, as though the user themself had clicked on it), for example within:
for (var i = a_parents.length-1; i >= 0; i--)
// check if node or root
if (a_parents.n_state & 48);
// select() invocation?



tigra - 1/15/2007 at 08:44 PM

sure, just call .select() on the found item after the parents opening loop.

jsuen - 1/16/2007 at 06:04 PM


I'm still a little hazy on calling select() in this function (as to whether the tree or item object version should be used). At the moment the following code:

function openItemByCaption (s_caption) {
// set to true when debugging the application
var B_DEBUG = false;
var o_tree = (TREES['MyTree']);

// find item with specified caption
var a_item = o_tree.find_item(s_caption);

for(var n=0; n < a_item.length; n++) {

// collect info about all item's parents
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];

// open all parents starting from root
for (var i = a_parents.length-1; i >= 0; i--) {
// check if node or root
if (a_parents.n_state & 48);

will open the corresponding branch fine, but the select call does nothing (with no Javascript errors returned in the browser).



tigra - 1/16/2007 at 07:07 PM

you're calling .select(..) on the tree object. Call it on the item object instead:;
instead of[0].n_id);

jsuen - 1/16/2007 at 07:22 PM


Thanks for this. I've replaced it with the call as you mentioned but it still does not bring up any results (i.e. clicking on the leaf normally will open up a new window, with the link designated to it). Is the select() function meant to simulate this behaviour?

Also, I do not know if it affects it in anyway, but the links I aim to call via select() are further javascript functions (which I can retrieve, but not call).



tigra - 1/17/2007 at 09:09 AM

no, select just marks the item as selected. you'll need to redirect the bowser or open the window in your code if this is what you want. You can get the URL associated with the item as o_item.a_config[1] and the target as o_item.a_config[2]['tw']

jsuen - 1/17/2007 at 09:24 PM

Thanks for your help. For some reason I always assumed select() would emulate the user clicking on the particular branch/leaf!

did the trick perfectly.



Back to forum: