I need assistance in creating a tree view using a list of items in ul li and JSON data. The tree view hierarchy should show the selected list item at the first level, followed by corresponding values from the JSON data at the next level. Please guide me on how to achieve this.
I have included an OUTPUT example of a treeview with selected li items along with my data.
JSON DATA The format will be similar for all list elements
data={
project_name: 'Sales1',
info: {
Value1: 'Value1',
Value2: 'Value2'
}
}
$(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");
}
});
})
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;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="projects">
<ul class="menu" id="projects-menu">
</ul>
</div>
Desired Output https://i.sstatic.net/7OXeX.png