EasyUI Forum
May 17, 2024, 07:15:42 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]All menus to tree  (Read 3388 times)
jega
Full Member
***
Posts: 191


View Profile
« on: October 31, 2018, 11:55:05 AM »

Hi.

As a test i have this

<a id="menu1" href="#" class="easyui-menubutton" data-options="menu:'#menu_1'">Menu 1</a>
<a id="menu2" href="#" class="easyui-menubutton" data-options="menu:'#menu_2'">Menu 2</a>

<ul id="tt" class="easyui-tree"></ul>

<div id="menu_1"></div>
<div id="menu_2"></div>

Menu items created from db

Have added the extended code found in another topic with getItems

Then i test with this code

      $('#tt').tree({
         checkbox:true,
         onlyLeafCheck:true,
         data:$('#menu_1').menu('getItems')
      });

Now i have a nice tree with nodes from menu_1.

I would like to have a tree with both menu_1 and menu_2. Any help ??

The best solution is that some code takes all menubutton on site, and make a tree of the whole menu structure.

Regards
jesper
« Last Edit: November 01, 2018, 04:34:56 AM by jega » Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #1 on: November 01, 2018, 02:04:27 AM »

The code below retrieves all the menubutton components on the page and build a tree based on the bound menus.
Code:
var nodes = [];
$('.m-btn').each(function(){
var opts = $(this).menubutton('options');
nodes.push({
text: opts.text,
children: $(opts.menu).menu('getItems')
})
});
$('#tt').tree({
checkbox:true,
onlyLeafCheck:true,
data:nodes
});
Logged
jega
Full Member
***
Posts: 191


View Profile
« Reply #2 on: November 01, 2018, 04:34:10 AM »

Thanks Jerry.

I knew there was an easy way to do it  Cheesy

Jesper
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!