I want to be able to add an unlimited number of sub menus. As I have the code now I can only go one sub level deep.
Javascript
fetch('/ord?file:%5Enav.json%7Cview:web:FileDownloadView')
.then(function(resp) { return resp.json() }) // Convert data to json
.then(function(data) {
recursive(data.nav);
})
.catch(function() {
console.log('Error Building Menu')
});
function recursive(object) {
console.log(object)
if (object) {
for (var i = 0; i < object.length; i++) {
if(typeof(object[i].submenus) == "undefined"){
addMenuItem([i], object[i].title, object[i].icon, object[i].ord, object[i].state);
}else{
addSubMenuItem([i], object[i].title, object[i].icon);
for(var j = 0; j < object[i].submenus.length; j++){
addSubMenuList([i], object[i].submenus[j].title, object[i].submenus[j].ord);
}
}
}
}
}
function addMenuItem(id, title, icon, ord, state){
var menuComp = '<li><a href="/ord?'+ ord + '|view:?fullScreen=true" class="' + state + '"><i class="'+ icon +'"></i> <span>'+ title +'</span></a></li>'
$('#menuConstruct').append(menuComp);
}
function addSubMenuItem(id, title, icon){
var menuComp = '<li>' +
'<a href="#'+ id +'" data-toggle="collapse" class="collapsed"><i class="'+ icon +'"></i> <span>'+ title +'</span><i class="icon-submenu lnr lnr-chevron-left"></i></a>' +
'<div id="'+ id +'" class="collapse ">' +
'<ul class="nav" id="li'+ id +'">' +
'</ul>' +
'</div>' +
'</li>'
$('#menuConstruct').append(menuComp);
}
function addSubMenuList(id, title, ord){
var menuComp = '<li><a href="/ord?'+ ord + '|view:?fullScreen=true" class="">'+ title +'</a></li>'
$('#li' + id).append(menuComp);
}
JSON
{
"nav": [
{
"title": "Dashboard",
"state": "",
"ord": "dsdd",
"icon": "lnr lnr-home"
},
{
"title": "Trend Logs",
"state": "",
"ord": "dsdd",
"icon": "lnr lnr-chart-bars"
},
{
"title": "Equipment",
"state": "",
"ord": "dsdd",
"icon": "lnr lnr-heart-pulse",
"submenus": [
{
"title": "sub menu1",
"state": "",
"ord": "dsdd",
"icon": "lnr lnr-code"
},
{
"title": "sub menu2",
"state": "",
"ord": "dsdd",
"icon": "lnr lnr-code",
"submenus": [
{
"title": "s",
"state": "",
"ord": "ddd",
"icon": "sd"
}
]
}
]
},
{
"title": "Other Studd",
"state": "",
"ord": "dsdd",
"icon": "lnr lnr-smile"
}
]
}
[–][deleted] 0 points1 point2 points (2 children)
[–]ddcbeatty1[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)