Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a scenario to create tree view with List of items in ul li and json data, based on my selection of list item a treeview should be created separately.In tree view heirarchy the first level will be the selected items from list and its corresponding next level will be the values from json data.please help me with this.

In the code below I have done a list.so when I select that list item on the right side a tree view should be created from json data

I have posted a link which show the OUTPUT of treeview I want.

treeview1 — Postimages[^]

What I have tried:

JSON
data={
  project_name: 'Sales1',
  info: {
    Value1: 'Value1',
    Value2: 'Value2'
   }
}


HTML
HTML
<div class="projects">
  <ul class="menu" id="projects-menu">
  </ul>
</div>

CSS
CSS
ul.menu {
  margin-top: 30px;
  list-style-type: none;
}

ul.menu li {
  background-color: #e0e0e0;
  padding: 8px 12px;
  border: solid 2px white;
  cursor: pointer;
  border: 3px solid #FFFFFF;
  border-radius: 10px;
}

ul.menu li:hover {
  background-color: #A9A9A9;
}

ul.menu li.selected {
  background-color: #23ac61;
}

ul.menu li.disabled:hover {
  background-color: #e0e0e0;
  cursor: default;
}


JQUERY
JavaScript
<pre>$(document).ready(function() {
  $('#projects-menu').append("<li  value='sales1'>Sales 1</li>")
 

  $(document).on('click', '#projects-menu > li', function(event) {
    event.preventDefault();
    if (event.ctrlKey) {
      if ($(this).hasClass('selected')) {
        $(this).removeClass('selected');
      } else {
        $(this).addClass("selected");
      }
    } else {
      $("#projects-menu > li").removeClass("selected");
      $(this).addClass("selected");
    }
  });

})
Posted
Updated 4-Sep-20 21:49pm
v3
Comments
Sandeep Mewara 5-Sep-20 3:37am    
And the query is? Where are you stuck?
Member 14931106 5-Sep-20 3:48am    
To create treeview when I select list item
Member 14931106 5-Sep-20 4:54am    
Any Solution?
[no name] 5-Sep-20 9:25am    
One usually starts by trying to add "any" item on the fly. You want us to guess at what stage you're at?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900