EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Ariovaldo on April 20, 2023, 03:20:43 PM



Title: [SOLVED] easyui-menubutton - create a menu with json
Post by: Ariovaldo on April 20, 2023, 03:20:43 PM
Hello,

I looked here in the forum and I didn't find an example or if it's possible to mount an easyui-menubutton with json dynamically  ???

Ari


Title: Re: easyui-menubutton - create a menu with json
Post by: jega on April 21, 2023, 11:03:23 PM
Hi.

Look at this http://www.jeasyui.com/forum/index.php?topic=3902.msg9291#msg9291


Title: Re: easyui-menubutton - create a menu with json
Post by: Ariovaldo on April 22, 2023, 07:42:52 AM
Hello Yega

thanks for the link  ;D

I ran it here and corrected a syntax error when closing the function, and everything worked ok.

I wonder how can I put a href on the object so that as soon as I click on the menu item it executes another function
 ???

Note: This menu is built based on user permissions


Title: Re: easyui-menubutton - create a menu with json
Post by: jega on April 22, 2023, 02:17:05 PM

Add an onClick to the functions and in the json data add iconClass, if needed, and additional items to tell what should happen in the onClick



var menuData = [{
        text: 'File',
        iconCls: 'icon-add',
        items: [{
            text: 'Exit',
            iconCls: 'icon-add',
            link: 'test.asp',
            linkType: 'window_blank',
            linkName: 'Testside'
        }]
    }];

    function createMenuBar(data, container){
      $.map(data, function(btn){
         var b = $('<a href="javascript:void(0)"></a>').appendTo(container);
         if (btn.items){
            b.menubutton($.extend({}, btn, {
               menu: createMenu(btn.items)
            }));           
         } else {
            b.linkbutton($.extend({}, btn, {
               plain: true,
               onClick: function(){
                  if (item.link) {
                     if (item.linkType == 'window_blank') {
                        window.open(item.link,item.linkName)
                     }
                  }
               }
            }));
         }
      });
      
      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, {
                  parent: (p?p.target:null),
                  onclick: function(){
                     if (item.link) {
                        if (item.linkType == 'window_blank') {
                           window.open(item.link,item.linkName)
                        }
                     }
                  }
               }));
               if (item.items){
                  var p1 = m.menu('findItem', item.text);
                  _create(item.items, p1);
               }
            });
         }
      }
   }


Title: [SOLVED] Re: easyui-menubutton - create a menu with json
Post by: Ariovaldo on April 23, 2023, 06:12:29 AM
Thanks ! Jega

saved me many hours of fighting :-)

Ari


Title: Re: easyui-menubutton - create a menu with json
Post by: jega on April 24, 2023, 12:30:54 AM
Please mark [SOLVED] in the subect. ;-)