EasyUI Forum
November 05, 2025, 07:10:04 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Get tree-like object from menu  (Read 9660 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« on: August 29, 2016, 02:01:29 AM »

Hi;

Is it possible to return a tree like object containing the menus and children from the menu() class ?

i.e
Code:
$('#mm').menu('getItems');

Thanks
« Last Edit: August 29, 2016, 02:06:33 AM by devnull » Logged

-- Licensed User --
tofix
Newbie
*
Posts: 4


View Profile
« Reply #1 on: August 30, 2016, 01:52:29 AM »

Not supported, I could not find that too.
Finally I ended up selecting all menuItems using jquery without having them as tree.
Because all items are just added before </body> from plain html this structure could not be extracted.

I added custom properties to the menu items and looped all of them with something like

 cmenu.menu('appendItem', {
                    parent: elem.target,
                    text: col.title,
                    custom: value
                });

  var menuItem = cmenu.menu('getItem', $('#customid')[0]); // contains custom
  cmenu.menu('enableItem', menuItem.target);
Logged
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #2 on: August 30, 2016, 02:07:33 AM »

This method can be extended as below:
Code:
<script>
(function($){
$.extend($.fn.menu.methods, {
getItems: function(jq){
return _items(jq);

function _items(m){
var items = [];
$(m).children('.menu-item').each(function(){
var item = jq.menu('getItem', this);
if (this.submenu){
item.children = _items(this.submenu);
}
items.push(item);
});
return items;
}
}
});
})(jQuery);
</script>
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!