EasyUI Forum
September 19, 2025, 10:53:13 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: new submenu  (Read 10324 times)
korenanzo
Guest
« on: February 29, 2016, 10:53:03 AM »

Hi,

in
http://www.jeasyui.com/forum/index.php?topic=668.msg1481#msg1481
 it is said that it is impossible to use appendItem  to append sub menu to an empty parent menu .

So How can I add a submenu after the main menu has been created (and may be showed)?

For example, I create a menu with three items and show() it;
then at runtime i need to add a 4th item with subitems.
thanks,
RIc
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #1 on: March 01, 2016, 06:50:01 AM »

You can call appendItem method to append a submenu. Please try this code.
Code:
// append a sub menu item
var item = $('#mm').menu('findItem', 'Open');  // find 'Open' item
$('#mm').menu('appendItem', {
parent: item.target,  // the parent item element
text: 'Open Excel',
iconCls: 'icon-excel',
onclick: function(){alert('Open Excel')}
});
Logged
korenanzo
Guest
« Reply #2 on: March 01, 2016, 08:09:30 AM »

But you said that the parent must already have children.

what if "Open" item does not yet exist?

I should create (appendItem ) the Open item and then create the submenu:
Code:
// #mm menu() already exist
//I create the Open Item
('#mm').menu('appendItem', {
  text: 'Open',
}

//and then create and append the submenu
var item = $('#mm').menu('findItem', 'Open');  // find 'Open' item
$('#mm').menu('appendItem', {
parent: item.target,  // the parent item element
text: 'Open Excel',
iconCls: 'icon-excel',
onclick: function(){alert('Open Excel')}
});

// but it does not work
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #3 on: March 01, 2016, 07:07:43 PM »

Some errors occur in your code. It should be:
Code:
$('#mm').menu('appendItem', {
  text: 'Open'
});
Logged
korenanzo
Guest
« Reply #4 on: March 02, 2016, 01:52:05 AM »

Some errors occur in your code. It should be:
Code:
$('#mm').menu('appendItem', {
  text: 'Open'
});

it was taken from a more complex example, the error is not present in the real code.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #5 on: March 02, 2016, 08:05:24 AM »

Please refer to this example http://jsfiddle.net/u16vv4gb/. It works fine.
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!