• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

(Recursively) populate cfmenu/cfmenuitem

Guest
Sep 07, 2009 Sep 07, 2009

Copy link to clipboard

Copied

So I have a cfmenu that I want to populate from a database. The cfmenu will have cfmenuitems inside parent cfmenuitems. The database that stores the menu items essentially has 4 colums: an "ID" column, a "Path" column, a "DisplayText" column, and a "ParentID" column. The ParentID column contains the ID of the row the menu item should be placed under.

I believe I would have to use some sort of recursive method or something as "ParentID" can point to a row that also has a "ParentID" pointing to some row (and on). Any idea how I might go about this? (Please ask for clarification if I am not being clear)

TOPICS
Advanced techniques

Views

791

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 07, 2009 Sep 07, 2009

Copy link to clipboard

Copied

If possible, rework your heirarchy to use a nested set (left/right), rather than an adjacency list (node/parent); adjacency lists really don't scale very well, because of all the recursion one needs to do to traverse it (like how you're wanting to do).  Google will turn up a bunch of stuff on this topic.  There is a CF implementation of a nested set hierarchy on RIAFORGE I think.

If you can do that, have a flick through the forum posts here from the last week or two, because a very similar question to yours has been asked and answered recently.  Lemme know if you can't find it, and I'll try to dig it out.

If you need to stick with adjacency lists, google "recursion examples": there'll be a stack of stuff covering your requirements already.  You could probably even search these forums and dig some stuff up on "recursive" or "recursion", although the search here is a bit rubbish, so Google might be a better option.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 07, 2009 Sep 07, 2009

Copy link to clipboard

Copied

Thanks, I didn't know that each method had a name. I found the links you were refering to. I will have to look into a nested set model. Thanks again!

(for future seekers...)

http://forums.adobe.com/message/2219066

http://stannard.net.au/blog/index.cfm/2008/6/13/Nested-Set-Trees-in-ColdFusion-v02

http://nstree.riaforge.org/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 07, 2009 Sep 07, 2009

Copy link to clipboard

Copied

LATEST

Cool.  Gizza yell if you need any help with the nested set stuff.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation