jega
|
|
« 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); } }); } } }
|