EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: jpierce on September 04, 2013, 02:36:25 PM



Title: how do you add a menu separator programmtically via appendItem?
Post by: jpierce on September 04, 2013, 02:36:25 PM
I know how to use menu-sep to add separators to menus at design-time, but how do you do that using appendItem?  I've tried everything I can think of.


Title: Re: how do you add a menu separator programmtically via appendItem?
Post by: stworthy on September 05, 2013, 01:19:20 AM
To append a menu separator, please download the updated menu plugin from http://www.jeasyui.com/easyui/plugins/jquery.menu.js and include it in your page.
Code:
$('#mm').menu('appendItem', {separator:true});


Title: Re: how do you add a menu separator programmtically via appendItem?
Post by: jpierce on September 05, 2013, 09:40:49 AM
That did the trick.  Thanks for the quick turnaround!

Will you be integrating that into a future version?


Title: Re: how do you add a menu separator programmtically via appendItem?
Post by: jpierce on October 01, 2013, 12:56:40 PM
Okay, now I've run into another difficulty.  How am I supposed to remove the dynamically added separator?  I wind up regenerating this menu often and have all these lines building up.  I can't figure out any way to get the seps with findItem in order to remove them.

There should be a way to do that, but to be honest a 'clear' method would be more useful for my present needs.

Also, can you send me these replacement jquery.menu.js files (or a link to them) in non-obfuscated format since I am a paid commercial subscriber?  It's great to have to obfuscated ones here for everyone to use, but it'd help me figure out/solve some of my own problems as well as provide you with better bug reporting if I had the non-obfuscated ones.


Title: Re: how do you add a menu separator programmtically via appendItem?
Post by: stworthy on October 01, 2013, 03:16:21 PM
Hi jpierce,

The 'removeItem' method can be used to remove menu item including the separator line.
Code:
var m = $('#mm');
m.menu('appendItem', {id:'s1',separator:true});  // append item separator line
m.menu('removeItem', $('#s1')[0]);  // remove it

Also, the updated menu plugin has been sent to you by email.


Title: Re: how do you add a menu separator programmtically via appendItem?
Post by: jpierce on October 01, 2013, 03:36:17 PM
Thanks, that worked, though it's a bit clunky to have to do it that way in my code.

I'd just like to plug again my request for a 'clear'.  Otherwise, here's what I'm having to do:

Code:
            $('.menu-text', menuElem)
                    .map(function (i, e) {
                        return e.textContent
                    })
                    .each(function (i, e) {
                        menuElem.menu('removeItem', menuElem.menu('findItem', e).target)
                    });

            if ($('#' + item.id + '_separator').length === 1) {
                menuElem.menu('removeItem', $('#' + item.id + '_separator')[0]);
            }

It's complicated by the fact that I have to do this for several menus (I have a sequence of "Presets" dropdown buttons for various fields).  It's just extra gross.


Title: Re: how do you add a menu separator programmtically via appendItem?
Post by: stworthy on October 01, 2013, 06:30:08 PM
The 'clear' method can be extended as below.
Code:
$.extend($.fn.menu.methods,{
clear: function(jq){
return jq.each(function(){
var m = $(this);
m.children('div.menu-item,div.menu-sep').each(function(){
m.menu('removeItem',this);
});
});
}
});


Title: Re: how do you add a menu separator programmtically via appendItem?
Post by: jpierce on October 03, 2013, 08:52:01 AM
Works great, thanks!


Title: Re: how do you add a menu separator programmtically via appendItem?
Post by: iceh on November 14, 2013, 11:41:22 AM
Any timeframe when this will make it in 1.3.5?