EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: evaj on September 14, 2012, 11:26:36 AM



Title: menu and submenu
Post by: evaj on September 14, 2012, 11:26:36 AM
Hi!

This is my first post.

I'm working with jquery and easyui and I have a doubt. I want to create a menu and submenu from javascript. This is my source code:

Code:
$("body").append("<div id='d0' class='easyui-menu' style='width:120px;'></div>");
$("#d0").menu("appendItem",{text:"one"});
$("#d0").menu("appendItem",{text:"two"});
$("#d0").menu("appendItem",{text:"three"});
var item = $("#d0").menu("findItem", "three");
$("#d0").menu("appendItem", {parent: item.target, text: "three.one"});
$("#d0").menu('show');

However the submenu is not showed when I put the cursor on item "three".

Also I tried to create a menu with html sentences in jquery:

Code:
$("body").append("<div id='d0' class='easyui-menu' style='width:120px;'></div>");
$("#d0").append("<div>one</div>");
$("#d0").append("<div>two</div>");
$("#d0").append("<div><span>three</span><div style='width:150px'><div>three.one</div></div></div>");
var item = $("#d0").menu("findItem", "three");
$("#d0").menu("appendItem", {parent: item.target, text: "three.two"});
$("#d0").menu("show");

With the same result as above.

So, how can I make a menu and submenus programatically?

Thank you in advance.

Regards.


Title: Re: menu and submenu
Post by: stworthy on September 14, 2012, 06:11:25 PM
Calling 'appendItem' method to append sub menu to an empty parent menu is invalid in current version. Your second code fragment is missing a statement to create the menu. Try this code:

Code:
$("body").append("<div id='d0' class='easyui-menu' style='width:120px;'></div>");
$("#d0").append("<div>one</div>");
$("#d0").append("<div>two</div>");
$("#d0").append("<div><span>three</span><div style='width:150px'><div>three.one</div></div></div>");
$("#d0").menu();  // to create the menu
var item = $("#d0").menu("findItem", "three");
$("#d0").menu("appendItem", {parent: item.target, text: "three.two"});
$("#d0").menu("show");


Title: Re: menu and submenu
Post by: evaj on September 15, 2012, 12:43:29 AM
Hi

I'm very delighted with your solution. Only one line of code and the menu and submenu is working as I expected.

Thank you very much.