$.get('/api/menu', function (menuItems) { var menuList = $('.layui-nav.layui-nav-tree'); menuList.empty(); menuItems.forEach(function (item) { var href = item.path || 'javascript:void(0);'; // 提供一个默认值 menuList.append('
  • ' + item.name + '
  • '); }); layui.element.render('nav', 'test'); });