layui 页面内部 打开顶级菜单
//左侧菜单缓存
setTimeout(function(){ let menus = []; $('#sideMenu a').each(function(){ if ($(this).attr('menu-id')){ let smitem = { "id": $(this).attr('menu-id'), "title": $(this).text() } menus.push(smitem); } }); if(menus.length>0){ sessionStorage.setItem('menus', JSON.stringify(menus)); } }, 1000);
//获取左侧菜单id
window.getMenuId = function (str) { let menus = JSON.parse(sessionStorage.getItem('menus')); let menuid = 0; if (menus.length>0){ for (var i = 0; i < menus.length; i++) { if (menus[i].title == str) { menuid = menus[i].id; break; } } } return menuid; }
//页面内点击打开顶级页面标签
top.layui.tab.addTabOnlyByElem("content", { id: getMenuId('新闻列表'), title: "新闻列表", url: '/admin/news/lists', close: "允许关闭" } )