EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: korenanzo on February 29, 2016, 10:53:03 AM



Title: new submenu
Post by: korenanzo 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


Title: Re: new submenu
Post by: jarry 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')}
});


Title: Re: new submenu
Post by: korenanzo 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


Title: Re: new submenu
Post by: jarry on March 01, 2016, 07:07:43 PM
Some errors occur in your code. It should be:
Code:
$('#mm').menu('appendItem', {
  text: 'Open'
});


Title: Re: new submenu
Post by: korenanzo 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.


Title: Re: new submenu
Post by: jarry on March 02, 2016, 08:05:24 AM
Please refer to this example http://jsfiddle.net/u16vv4gb/. It works fine.