EasyUI Forum

General Category => Bug Report => Topic started by: thiago_brum on April 27, 2018, 07:01:28 AM



Title: Menu Click Bug
Post by: thiago_brum on April 27, 2018, 07:01:28 AM
Hello. I upgrade from 1.5 to 1.5.5.
Now, when I click on a menu with submenus (
that is, without URL ou Javascript action defined), it tries to open a UNDEFINED page,
instead of displaying the submenu. How can I fix this?


Title: Re: Menu Click Bug
Post by: thiago_brum on April 27, 2018, 07:05:57 AM
My code...

    var data = ".json_encode($itens_menu[$sistema]).";

    createMenuBar(data, '#top-menu');
    
    function createMenuBar(data, container){
     $.map(data, function(btn){
         var b = $('<a href=\''+(btn.url != '' ? btn.url : '#')+'\'></a>').appendTo(container); // CLICK ERROR HERE
         if (btn.items){
             b.menubutton($.extend({}, btn, {
                 menu: createMenu(btn.items),
                 iconCls: btn.icon
             }));            
         } else {
             b.linkbutton($.extend({}, btn, {
                 plain: true,
                 iconCls: btn.icon
             }));
         }
     });
    
     function createMenu(items){
         var m = $('<div></div>').appendTo('body').menu();
         _create(items);
         return m;
 
         function _create(items, p){
             $.map(items, function(item){
                 m.menu('appendItem', $.extend({}, item, {
                     iconCls: item.icon,
                     href: item.url,
                     parent: (p?p.target:null)
                 }));
                 if (item.items){
                     var p1 = m.menu('findItem', item.text);
                     _create(item.items, p1);
                 }
             });
         }
     }
    }




Title: Re: Menu Click Bug
Post by: stworthy on April 27, 2018, 05:31:02 PM
Please look at your code:
Code:
var b = $('<a href=\''+(btn.url != '' ? btn.url : '#')+'\'></a>').appendTo(container);

If you are missing the 'url' property, the '<a href="undefined"...>' will be rendered and will navigate you to a undefined page. To solve this issue, please use this code instead.
Code:
var b = $('<a href=\''+(btn.url != undefined ? btn.url : '#')+'\'></a>').appendTo(container);

This example works fine.
http://code.reloado.com/ewecip3/edit#html,live


Title: Re: Menu Click Bug
Post by: thiago_brum on April 29, 2018, 06:44:17 AM
Thanks for the help but doesn't fix my problem. In your example, if I click on the MenuButton, nothing happens. In 1.5 version, It's shows(open) the submenus (Item1,Item2).


Title: Re: Menu Click Bug
Post by: stworthy on April 29, 2018, 07:38:13 PM
If you wish to display the drop-down menu by clicking the menubutton, please set 'showEvent' property to 'click'.