Home > Archive > ASP > February 2006 > Displaying Preorder Tree Traversal Hierarchy in ASP?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Displaying Preorder Tree Traversal Hierarchy in ASP?
|
|
| FrankEBailey 2006-02-13, 6:55 pm |
| I've been reading up on Modified Preorder Tree Traversal and it's
definitely ideal for the kind of tree structures I need to model for my
company's multi-level sales hierarchy. I've implemented the database
side already in SQL Server 2000 and can retrieve all child nodes based
on the left and right IDs of the current node. My problem is displaying
the tree so that correct indentation can be used to show the
relationships between the parents and their respective child nodes.
I'm aiming for this type of display:
Organic_Produce
- Fruit
- Banana
- Cherry
- Orange
- Vegetables
- Potatoes
- Savoury Potatoes
- Sweet Potatoes
- Zucchini
etc.
Now, I know a recursive function of some sort is needed, and I read on
this page http://www.sitepoint.com/print/hier...l-data-database how
to create the function in PHP, however I don't have the first clue how
to translate this into VBScript for implementation in ASP. If anyone
has perhaps an example of how a function to display MPTT-type
hierarchical data via VBScript, I will greatly appreciate any
assistance you might be able to offer.
Thanks in advance!
Frank
| |
| FrankEBailey 2006-02-14, 3:55 am |
| Can anyone help me on this?
| |
| Anthony Jones 2006-02-18, 6:55 pm |
| >I've been reading up on Modified Preorder Tree Traversal and it's
>definitely ideal for the kind of tree structures
<snip>
>Now, I know a recursive function of some sort is needed
Actually I think the whole point of the left right values in this technique
is to avoid having recursive functions which can become very slow.
All you need is a single recordset ordered by Left. The code is something
like this:-
Dim lLastLeft
Dim lDepth
Dim alRight
lDepth = 0
lLastLeft = rs("left")
ReDim alRight(4)
alRight(lDepth) = rs("right")
RenderRecord rs, lDepth
rs.MoveNext
Do Until rs.EOF
Do Until alRight(lDepth) > rs("left")
lDepth = lDepth - 1
Loop
If lDepth = UBound(alDepth) Then ReDim Preserve alRight(lDepth * 2)
lDepth = lDepth + 1
alRight(lDepth) = rs("right")
RenderRecord rs, lDepth
rs.MoveNext
Loop
Anthony.
|
|
|
|
|