1.首先是数据库表必然包含以下几个字段Id ,ParnetId,Url,Name等

  1. create table dbo.Module (
  2. Id uniqueidentifier not null constraint DF_Module_Id default newid(),
  3. Name varchar(255) collate Chinese_PRC_CI_AS not null constraint DF__Module__Name__46F27704 default ' ',
  4. Url varchar(255) collate Chinese_PRC_CI_AS not null constraint DF__Module__Url__47E69B3D default ' ',
  5. IsLeaf bit not null constraint DF__Module__IsLeaf__4AC307E8 default (1),
  6. IsAutoExpand bit not null constraint DF__Module__IsAutoEx__4BB72C21 default (0),
  7. IconName varchar(255) collate Chinese_PRC_CI_AS not null constraint DF__Module__IconName__4CAB505A default ' ',
  8. Status int not null constraint DF__Module__Status__4D9F7493 default (1),
  9. ParentName varchar(255) collate Chinese_PRC_CI_AS not null constraint DF__Module__ParentNa__4E9398CC default ' ',
  10. SortNo int not null constraint DF__Module__SortNo__507BE13E default (0),
  11. ParentId uniqueidentifier null
  12. )

2.服务端很简单,只要输出json格式就可以了

[
{
"Id": "bedb41a2-f310-4575-af99-01be01adda93",
"Name": "test",
"Url": "/",
"ParentId": "bedb41a2-f310-4775-af99-01be08adda93",
"IconName": "fa-users",
"Checked": false
},
{
"Id": "bedb41a2-f310-4775-af99-01be08adda93",
"Name": "角色管理",
"Url": "RoleManager.html",
"ParentId": "7580672f-a390-4bb6-982d-9a4570cb5199",
"IconName": "fa-users",
"Checked": false
},
{
"Id": "0031262c-689c-4b96-bae2-2c9d67076ade",
"Name": "流程设计",
"Url": "/flowmanage/flowdesign/index",
"ParentId": "7580672f-a390-4bb6-982d-9a4570cb5199",
"IconName": "fa-anchor",
"Checked": false
},
{
"Id": "e8dc5db6-4fc4-4795-a1cc-681cbcceec91",
"Name": "资源管理",
"Url": "/ResourceManager/Index",
"ParentId": "7580672f-a390-4bb6-982d-9a4570cb5199",
"IconName": "fa-calculator",
"Checked": false
},
{
"Id": "ef386d5d-cd58-43c0-a4ab-80afd0dbcd6c",
"Name": "用户管理",
"Url": "UserManager.html",
"ParentId": "7580672f-a390-4bb6-982d-9a4570cb5199",
"IconName": "fa-user",
"Checked": false
},
{
"Id": "7580672f-a390-4bb6-982d-9a4570cb5199",
"Name": "基础配置",
"Url": " ",
"ParentId": null,
"IconName": "fa-cog",
"Checked": false
},
{
"Id": "92b00259-2d15-43e7-9321-adffb29e8bf2",
"Name": "表单设计",
"Url": "/flowmanage/formdesign/index",
"ParentId": "7580672f-a390-4bb6-982d-9a4570cb5199",
"IconName": "fa-anchor",
"Checked": false
},
{
"Id": "bc80478d-0547-4437-9cff-be4b40144bdf",
"Name": "模块管理",
"Url": "ModuleManager.html",
"ParentId": "7580672f-a390-4bb6-982d-9a4570cb5199",
"IconName": "fa-file-code-o",
"Checked": false
},
{
"Id": "069475e3-c997-487a-9f29-e6a864c5c1d4",
"Name": "应用功能",
"Url": "/",
"ParentId": null,
"IconName": "fa-bars",
"Checked": false
},
{
"Id": "a94d5648-c2a9-405e-ba6f-f1602ec9b807",
"Name": "分类管理",
"Url": "/CategoryManager/Index",
"ParentId": "7580672f-a390-4bb6-982d-9a4570cb5199",
"IconName": "fa-archive",
"Checked": false
},
{
"Id": "6a9e1346-0c01-44d2-8eb1-f929fdab542a",
"Name": "部门管理",
"Url": "/OrgManager/Index",
"ParentId": "7580672f-a390-4bb6-982d-9a4570cb5199",
"IconName": "fa-plus-square-o",
"Checked": false
},
{
"Id": "89c3bfbe-246f-4112-8eb1-b6789da54202",
"Name": "进出库管理",
"Url": "/StockManager/Index",
"ParentId": "069475e3-c997-487a-9f29-e6a864c5c1d4",
"IconName": "fa-archive",
"Checked": false
},
{
"Id": "9486ff22-b696-4d7f-8093-8a3e53c45453",
"Name": "流程处理",
"Url": "/FlowManage/FlowInstances/Index",
"ParentId": "069475e3-c997-487a-9f29-e6a864c5c1d4",
"IconName": "fa-clock-o",
"Checked": false
}
]

3.重点在前端实现

(1)前端实现list转tree

  1. /**
  2. *
  3. *
  4. */
  5. var LTT, list, ltt;
  6.  
  7. function pluck(collection, key) {
  8. return collection.map(function (item) {
  9. return item[key];
  10. });
  11. }
  12.  
  13. function unique(collection) {
  14. return collection.filter(function (value, index, array) {
  15. return array.indexOf(value) === index;
  16. });
  17. }
  18.  
  19. function sortBy(collection, propertyA, propertyB) {
  20. return collection.sort(function (a, b) {
  21. if (a[propertyB] < b[propertyB]) {
  22. if (a[propertyA] > b[propertyA]) {
  23. return 1;
  24. }
  25. return -1;
  26. } else {
  27. if (a[propertyA] < b[propertyA]) {
  28. return -1;
  29. }
  30. return 1;
  31. }
  32. });
  33. };
  34.  
  35. LTT = (function () {
  36. LTT.prototype.groupParent = [];
  37.  
  38. LTT.prototype.key_id = 'id';
  39.  
  40. LTT.prototype.key_parent = 'parent';
  41.  
  42. LTT.prototype.key_child = 'child';
  43.  
  44. LTT.prototype.options = {};
  45.  
  46. function LTT(list, options) {
  47. this.list = list;
  48. this.options = options != null ? options : {};
  49. this.ParseOptions();
  50. //js不排序
  51. //this.list = sortBy(this.list, this.key_parent, this.key_id);
  52. this.groupParent = unique(pluck(this.list, this.key_parent));
  53. return this;
  54. }
  55.  
  56. LTT.prototype.ParseOptions = function () {
  57. var that = this;
  58. ['key_id', 'key_parent', 'key_child'].forEach(function (item) {
  59. if (typeof that.options[item] !== 'undefined') {
  60. that[item] = that.options[item];
  61. }
  62. });
  63. };
  64.  
  65. LTT.prototype.GetParentItems = function (parent) {
  66. var item, result, _i, _len, _ref;
  67. result = [];
  68. _ref = this.list;
  69. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  70. item = _ref[_i];
  71. if (item[this.key_parent] === parent) {
  72. result.push(item);
  73. }
  74. }
  75. return result;
  76. };
  77.  
  78. LTT.prototype.GetItemById = function (id) {
  79. var item, _i, _len, _ref;
  80. _ref = this.list;
  81. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  82. item = _ref[_i];
  83. if (item[this.key_id] === id) {
  84. return item;
  85. }
  86. }
  87. return false;
  88. };
  89.  
  90. LTT.prototype.GetTree = function () {
  91. var child, i, obj, parentId, result, _i, _j, _len, _len1, _ref;
  92. result = [];
  93. _ref = this.groupParent;
  94. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  95. parentId = _ref[_i];
  96. obj = this.GetItemById(parentId);
  97. child = this.GetParentItems(parentId);
  98. if (obj === false) {
  99. for (_j = 0, _len1 = child.length; _j < _len1; _j++) {
  100. i = child[_j];
  101. result.push(i);
  102. }
  103. } else {
  104. obj[this.key_child] = child;
  105. }
  106. }
  107. return result;
  108. };
  109.  
  110. return LTT;
  111.  
  112. })();

使用方法

  1. //
  2. var ltt = new LTT(data, {
  3. key_id: 'Id',
  4. key_parent: 'ParentId',
  5. key_child:'Children'
  6. });
  7. var tree = ltt.GetTree();

(2)菜单html拼接实现

  1. //实现菜单
  2. function getDom(data) {
  3. if(!data){return ''}
  4. var _html='';
  5. $.each(data,function(i) {
  6. var row = data[i];
  7. if (row.hasOwnProperty("Children")) {
  8. _html += '<li>';
  9. _html += '<a href="#" class="dropdown-toggle">';
  10. _html += '<i class="menu-icon fa ' + row.IconName + '"></i>';
  11. _html += '<span class="menu-text nav-label">' + row.Name + '</span > ';
  12. _html += '<b class="arrow fa fa-angle-down"></b>';
  13. _html += '</a >';
  14. _html += '<b class="arrow"></b>';
  15. _html += '<ul class="submenu">';
  16. _html += getDom(row.Children);
  17. _html += '</ul>';
  18. _html += '</li>';
  19. } else {
  20. _html += '<li class="" id="' + row.Id + '">';
  21. _html += '<a class="J_menuItem" href="' + row.Url + '">';
  22. _html += '<i class="menu-icon fa ' + row.IconName + '"></i>';
  23. _html += '<span class="menu-text">' + row.Name + '</span>';
  24. _html += '</a>';
  25. _html += '<b class="arrow"></b>';
  26. _html += '</li>';
  27. }
  28.  
  29. });
  30. return _html;
  31. };

(3)最后实现

  1. $.ajax({
  2. url: 'Api/Menu/GetTree',
  3. type: 'get',
  4. dataType: 'json',
  5. success: function (data) {
  6. var ltt = new LTT(data, {
  7. key_id: 'Id',
  8. key_parent: 'ParentId',
  9. key_child:'Children'
  10. });
  11. var tree = ltt.GetTree();
  12. console.log(tree);
  13. var html = getDom(tree);
  14. $("#side-menu").prepend(html);
  15. }
  16. })

附上ace官网地址

http://ace.jeka.by/index.html

基于Ace Admin 的菜单栏实现的更多相关文章

  1. 并发编程概述 委托(delegate) 事件(event) .net core 2.0 event bus 一个简单的基于内存事件总线实现 .net core 基于NPOI 的excel导出类,支持自定义导出哪些字段 基于Ace Admin 的菜单栏实现 第五节:SignalR大杂烩(与MVC融合、全局的几个配置、跨域的应用、C/S程序充当Client和Server)

    并发编程概述   前言 说实话,在我软件开发的头两年几乎不考虑并发编程,请求与响应把业务逻辑尽快完成一个星期的任务能两天完成绝不拖三天(剩下时间各种浪),根本不会考虑性能问题(能接受范围内).但随着工 ...

  2. .NET Core的响应式框架,基于Ace Admin框架菜单导航,Bootstrap布局,fontAwesome图标,内嵌Iframe用EasyUI做数据绑定,动态配置列表,动态配置表单

    netnrf 响应式框架 用于快速开发的响应式框架 演示:https://rf2.netnr.com v3.x 前端采用 jQuery + Bootstrap + EasyUI + AceAdmin ...

  3. YII与Ace Admin 的集成

    目录 一. 前言... 1 二.为什么要使用YII+ace. 1 三.新建YII模块... 1 四.如何修改模板... 3 五.注意的地方... 4 六.整合的不足之处... 4 一. 前言 yii- ...

  4. Ace Admin 使用教程

    (原) 公司项目要换框架,然后丢了一套国外的给我,ace admin,本想着拿来改改,翻翻百度就能用的,可它是国外的啊,国内普及率又不高,没办法,硬着头皮一点点啃英文文档吧. File(文件) 简介: ...

  5. 改造 Ace Admin 模板的 ace_tree 组件的 folderSelect 样式

    *注:我用的Ace Admin版本为1.3.4 Ace Admin 是一个轻量,功能丰富,HTML5.响应式.支持手机及平板电脑上浏览的优秀管理后台模板. 关于tree的使用,html文件夹下tree ...

  6. Ace admin 如何实现类似于freamset加载页面

    如上标题所述,ace admin做后台页面的时候,可以实现类似于用freamset的功能,但是ace admin做的比freamset更好,他可以用异步加载的形式展示,而加载的页面的内容可以尽可能的少 ...

  7. ace admin 左侧菜单定位

    后台模版来自:Ace Admin http://ace.jeka.by/form-elements.html 左侧菜单,通过js根据url来判断显示哪块 window.location.pathnam ...

  8. c++ 跨平台线程同步对象那些事儿——基于 ace

    前言 ACE (Adaptive Communication Environment) 是早年间很火的一个 c++ 开源通讯框架,当时 c++ 的库比较少,以至于谈 c++ 网络通讯就绕不开 ACE, ...

  9. 基于ACE的c++线程封装

    1. 基本需求 1) 一个基类,其某个方法代表一个线程的生命运行周期.之后通过继承自这个基类来实现个性化线程类: 2) 具备类似QObject的定时器设置功能: 3) 提供在线程对象中同步和异步执行方 ...

随机推荐

  1. BZOJ4198:[NOI2015]荷马史诗

    浅谈\(Huffman\)树:https://www.cnblogs.com/AKMer/p/10300870.html 题目传送门:https://lydsy.com/JudgeOnline/pro ...

  2. BMP格式转JPEG格式

    int Bmp2Jpg(const char *bmp_data, const char *jeg_file, const int width, const int height) { int ret ...

  3. 蓝桥杯 历届试题 PREV-33 兰顿蚂蚁

    历届试题 兰顿蚂蚁   时间限制:1.0s   内存限制:256.0MB 问题描述 兰顿蚂蚁,是于1986年,由克里斯·兰顿提出来的,属于细胞自动机的一种. 平面上的正方形格子被填上黑色或白色.在其中 ...

  4. 机器学习:调整kNN的超参数

    一.评测标准 模型的测评标准:分类的准确度(accuracy): 预测准确度 = 预测成功的样本个数/预测数据集样本总数: 二.超参数 超参数:运行机器学习算法前需要指定的参数: kNN算法中的超参数 ...

  5. 【转】 Pro Android学习笔记(八一):服务(6):复杂数据Parcel

    目录(?)[-] 自定义的Parcelable类 AIDL文件 服务的实现 Client的实现 同步和异步     文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处 ...

  6. eclipse中删除tomcat server 导致不能重新创建该server

    定位到:workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings 1 打开org.eclipse.jst.server.tomca ...

  7. Mycat-server-1.6.5 常见分片方式

    Mycat-server-1.6.5 常见分片方式 1 安装 [root@hongquan1 soft]# tar zxvf Mycat-server-1.6.5-release-2018012222 ...

  8. spring--AOP--日志---demo1---bai

    AOP日志DEMO1: 实体类: package com.etc.entity; import org.aspectj.lang.annotation.Pointcut; public class U ...

  9. json例子--bai

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  10. paramiko监控 windows服务器 被监控服务器只需要安装openssh服务即可基于wmic完成大部分监控

    #!/usr/bin/python #-*- coding: UTF-8 -*- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...