EasyUI Forum
September 14, 2025, 12:13:27 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: menu and submenu  (Read 12818 times)
evaj
Newbie
*
Posts: 13


View Profile Email
« 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.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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");
Logged
evaj
Newbie
*
Posts: 13


View Profile Email
« Reply #2 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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!