EasyUI Forum
June 19, 2024, 04:41:22 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED] easyui-menubutton - create a menu with json  (Read 2235 times)
Ariovaldo
Newbie
*
Posts: 27


Ariovaldo - São Paulo - SP


View Profile WWW Email
« 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  Huh

Ari
« Last Edit: April 24, 2023, 03:46:11 AM by Ariovaldo » Logged

programming is easy, it is difficult to make programs
jega
Full Member
***
Posts: 191


View Profile
« Reply #1 on: April 21, 2023, 11:03:23 PM »

Hi.

Look at this http://www.jeasyui.com/forum/index.php?topic=3902.msg9291#msg9291
Logged
Ariovaldo
Newbie
*
Posts: 27


Ariovaldo - São Paulo - SP


View Profile WWW Email
« Reply #2 on: April 22, 2023, 07:42:52 AM »

Hello Yega

thanks for the link  Grin

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
 Huh

Note: This menu is built based on user permissions
« Last Edit: April 22, 2023, 07:45:01 AM by Ariovaldo » Logged

programming is easy, it is difficult to make programs
jega
Full Member
***
Posts: 191


View Profile
« Reply #3 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);
               }
            });
         }
      }
   }
Logged
Ariovaldo
Newbie
*
Posts: 27


Ariovaldo - São Paulo - SP


View Profile WWW Email
« Reply #4 on: April 23, 2023, 06:12:29 AM »

Thanks ! Jega

saved me many hours of fighting :-)

Ari
« Last Edit: April 24, 2023, 03:42:23 AM by Ariovaldo » Logged

programming is easy, it is difficult to make programs
jega
Full Member
***
Posts: 191


View Profile
« Reply #5 on: April 24, 2023, 12:30:54 AM »

Please mark [SOLVED] in the subect. ;-)
 
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!