embedding sub menus

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
autumnnn
Beginner
Beginner
Posts: 2
Joined: Thu Sep 25, 2003 10:07 am

embedding sub menus

Post by autumnnn »

Hi,

I'm dynamically generating the menus from a database and I need to put the sub menu inside the top level menu like so:

Code: Select all


with(milonic=new menuname("Home")){
style=menuStyle;
aI("text=Item 1;url=http://milonic.com/cbuy.php;");
aI("text=Item 2 with submenu;showmenu=Sub;");

	with(milonic=new menuname("Sub")){
	style=menuStyle;
	aI("text=Sub1;url=http://www.spamcop.net/;");
	aI("text=Sub2;url=http://www.spamcop.net/;");
	}
}

aI("text=Item 3;url=http://milonic.com/forum/;");
}

this works fine and Item 2 shows the submenu items ok. but it just adds Item 3 to the sub menu not the top level menu.

I hope that makes sense. Any suggestions?

thanks
A
User avatar
Hergio
Milonic God
Milonic God
Posts: 1123
Joined: Wed Jun 12, 2002 7:46 pm
Location: Rochester, NY

Post by Hergio »

Some people have tried and done this before. I think the reason its doing that is each aI call reference the CURRENTLY building menu, so if you start a new menu with the with(milonic=... then any subsequent aI will be added to the newest one.

You should probably change the way you dynamically generate your menus. Rather than do it depth-first like you are trying to do, create it breadth-first. Basically what I mean is, you'll have to create the menu code in layers, not hierarchial. I know this maynot be how you have things stored in your database or whatever dynamic source, but its how it needs to be done at the moment.

Hey Andy, this brings up an interesting point. What if one wanted to add items after the fact? Can it be done currently, or easily with a few changes? Like can one say with( getMenuByName("main1') ){ ...add more aI items... } or something to that effect (cuz I tried this and it dont work).

I was thinking maybe making the aI accept another parameter called menu where you could specify what menu that particular aI would be adding to. Like for default, you could say menu=this or not put it in and it would assume the currently building menu. But if you put in, say, menu=main1 then it would add itself to main1's list of items. What do you think?
Dave Hergert
Software Engineer
"Helping to make the menu better, one :?: at a time."
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Post by Andy »

This has already been done.

There is a new function called insertItem that can be used to insert a new menu item from anywhere within the menu data file. The idea is that users who need menus built based on information from different places can do so. It's also another way of building menus.

What you do is declare a menu as normal and then, for example, at the bottom of the data file insert a menu item into a menu that was previously built.

I'm really going to have to get a demo of this as it's more complicated to exaplain than it is to show you.

I'm working on demos now so should have something soon.

Cheers
Andy
autumnnn
Beginner
Beginner
Posts: 2
Joined: Thu Sep 25, 2003 10:07 am

Post by autumnnn »

fantastic!

that should solve my problem. would you mind just posting a little message here saying where the demo is? (when it's done)

I would really appreciate it.

thanks
A
Post Reply