JavaScript.CoolDev.Com Support Forums

Any questions related to JavaScript menu and JavaScript tree menu by Javascript.CoolDev.Com

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

dynamic node linking

 
Post new topic   Reply to topic    JavaScript.CoolDev.Com Forum Index -> COOLjsTree
Author Message
jmacfarland



Joined: 18 Aug 2003
Posts: 2

PostPosted: Mon Aug 18, 2003 3:39 pm    Post subject: dynamic node linking Reply with quote

First of all--this is the best javaScript Tree on the net-thanks for making a great product.

I'm not a jScript guru or anything and I've been trying to figure out some of the functions to make something work without much success.

What I want to do is to dynamically link using a function that looks at which node I selected, see where it is in the list, separate white space and link to that spot. Let me give an example:

here are a few sample links/nodes of the tree1_nodes.js

[{"id":1},'Directory 1', null, null,
[{"id":2},'Page 1', SOME FUNCTION, null,],
[{"id":3},'Page 2', SOME FUNCTION, null,],
],
[{"id":4},'Directory 2', null, null,
[{"id":5},'Page 3', SOME FUNCTION, null,],
[{"id":6},'Page 4', SOME FUNCTION, null,],
];

Let's say I click Directory 1 and then Page 1 on the actual tree menu

I want SOME FUNCTION to go to index.php?Top=Directory1&Sub1=Page1&Sub2=null

on index.php I'll get the values of the querystring, parse them out and append them with.php or whatever to include them in the page.

basically I want it to look through the node structure, see if it has a parent node and then add the node structure to the query string.

On index.php I will include the page between the header and footer based on the querystring using $_GET

This is WHY I want to do it this way:

That way I can create a directory structure on the server that matches my tree node structure making it simple for anyone else who takes the code to recognize what's going on. That means my directory structure has a folder called "Directory1" (no spaces) and a page called "Page1.php" (no spaces) in that directory.
The function would take white spaces out so it could just read the caption of the node and put it in the query string.

problem is, I'm clueless....anyone have some ideas?

Thanks in advance
Back to top
AlexKunin
Developer


Joined: 03 Jan 2003
Posts: 1191

PostPosted: Tue Sep 02, 2003 11:15 am    Post subject: Reply with quote

Here is some JavaScript code for you. It must be placed into the place where TREE1_NODES is defined, right after the definition.
Code:
function walk_nodes(nodes, o, level, prefix) {
   if (!level)
      level = 0;
   for (var i = o ? o : 0; i < nodes.length; i++) {
      if (!nodes[i] || nodes[i].format)
         continue;
      var j = nodes[i][0].id ? 1 : 0;
      var url, caption = nodes[i][j].replace(/ /, '');
      if (level && level >= 1) {
         url = prefix + '&Sub' + level + '=' + caption;
         nodes[i][j + 1] = url;
      } else
         url = 'index.php?Top=' + caption;
      if (nodes[i][j + 3] && nodes[i][j + 3].format)
         j++;
      nodes[i] = walk_nodes(nodes[i], j + 3, level + 1, url);
   }

   return nodes;
}

TREE1_NODES = walk_nodes(TREE1_NODES);
Back to top
Display posts from previous:   
Post new topic   Reply to topic    JavaScript.CoolDev.Com Forum Index -> COOLjsTree All times are GMT
Page 1 of 1