基于Ace Admin 的菜单栏实现
1.首先是数据库表必然包含以下几个字段Id ,ParnetId,Url,Name等
- create table dbo.Module (
- Id uniqueidentifier not null constraint DF_Module_Id default newid(),
- Name varchar(255) collate Chinese_PRC_CI_AS not null constraint DF__Module__Name__46F27704 default ' ',
- Url varchar(255) collate Chinese_PRC_CI_AS not null constraint DF__Module__Url__47E69B3D default ' ',
- IsLeaf bit not null constraint DF__Module__IsLeaf__4AC307E8 default (1),
- IsAutoExpand bit not null constraint DF__Module__IsAutoEx__4BB72C21 default (0),
- IconName varchar(255) collate Chinese_PRC_CI_AS not null constraint DF__Module__IconName__4CAB505A default ' ',
- Status int not null constraint DF__Module__Status__4D9F7493 default (1),
- ParentName varchar(255) collate Chinese_PRC_CI_AS not null constraint DF__Module__ParentNa__4E9398CC default ' ',
- SortNo int not null constraint DF__Module__SortNo__507BE13E default (0),
- ParentId uniqueidentifier null
- )
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
- /**
- *
- *
- */
- var LTT, list, ltt;
- function pluck(collection, key) {
- return collection.map(function (item) {
- return item[key];
- });
- }
- function unique(collection) {
- return collection.filter(function (value, index, array) {
- return array.indexOf(value) === index;
- });
- }
- function sortBy(collection, propertyA, propertyB) {
- return collection.sort(function (a, b) {
- if (a[propertyB] < b[propertyB]) {
- if (a[propertyA] > b[propertyA]) {
- return 1;
- }
- return -1;
- } else {
- if (a[propertyA] < b[propertyA]) {
- return -1;
- }
- return 1;
- }
- });
- };
- LTT = (function () {
- LTT.prototype.groupParent = [];
- LTT.prototype.key_id = 'id';
- LTT.prototype.key_parent = 'parent';
- LTT.prototype.key_child = 'child';
- LTT.prototype.options = {};
- function LTT(list, options) {
- this.list = list;
- this.options = options != null ? options : {};
- this.ParseOptions();
- //js不排序
- //this.list = sortBy(this.list, this.key_parent, this.key_id);
- this.groupParent = unique(pluck(this.list, this.key_parent));
- return this;
- }
- LTT.prototype.ParseOptions = function () {
- var that = this;
- ['key_id', 'key_parent', 'key_child'].forEach(function (item) {
- if (typeof that.options[item] !== 'undefined') {
- that[item] = that.options[item];
- }
- });
- };
- LTT.prototype.GetParentItems = function (parent) {
- var item, result, _i, _len, _ref;
- result = [];
- _ref = this.list;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- item = _ref[_i];
- if (item[this.key_parent] === parent) {
- result.push(item);
- }
- }
- return result;
- };
- LTT.prototype.GetItemById = function (id) {
- var item, _i, _len, _ref;
- _ref = this.list;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- item = _ref[_i];
- if (item[this.key_id] === id) {
- return item;
- }
- }
- return false;
- };
- LTT.prototype.GetTree = function () {
- var child, i, obj, parentId, result, _i, _j, _len, _len1, _ref;
- result = [];
- _ref = this.groupParent;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- parentId = _ref[_i];
- obj = this.GetItemById(parentId);
- child = this.GetParentItems(parentId);
- if (obj === false) {
- for (_j = 0, _len1 = child.length; _j < _len1; _j++) {
- i = child[_j];
- result.push(i);
- }
- } else {
- obj[this.key_child] = child;
- }
- }
- return result;
- };
- return LTT;
- })();
使用方法
- //
- var ltt = new LTT(data, {
- key_id: 'Id',
- key_parent: 'ParentId',
- key_child:'Children'
- });
- var tree = ltt.GetTree();
(2)菜单html拼接实现
- //实现菜单
- function getDom(data) {
- if(!data){return ''}
- var _html='';
- $.each(data,function(i) {
- var row = data[i];
- if (row.hasOwnProperty("Children")) {
- _html += '<li>';
- _html += '<a href="#" class="dropdown-toggle">';
- _html += '<i class="menu-icon fa ' + row.IconName + '"></i>';
- _html += '<span class="menu-text nav-label">' + row.Name + '</span > ';
- _html += '<b class="arrow fa fa-angle-down"></b>';
- _html += '</a >';
- _html += '<b class="arrow"></b>';
- _html += '<ul class="submenu">';
- _html += getDom(row.Children);
- _html += '</ul>';
- _html += '</li>';
- } else {
- _html += '<li class="" id="' + row.Id + '">';
- _html += '<a class="J_menuItem" href="' + row.Url + '">';
- _html += '<i class="menu-icon fa ' + row.IconName + '"></i>';
- _html += '<span class="menu-text">' + row.Name + '</span>';
- _html += '</a>';
- _html += '<b class="arrow"></b>';
- _html += '</li>';
- }
- });
- return _html;
- };
(3)最后实现
- $.ajax({
- url: 'Api/Menu/GetTree',
- type: 'get',
- dataType: 'json',
- success: function (data) {
- var ltt = new LTT(data, {
- key_id: 'Id',
- key_parent: 'ParentId',
- key_child:'Children'
- });
- var tree = ltt.GetTree();
- console.log(tree);
- var html = getDom(tree);
- $("#side-menu").prepend(html);
- }
- })
附上ace官网地址
http://ace.jeka.by/index.html
基于Ace Admin 的菜单栏实现的更多相关文章
- 并发编程概述 委托(delegate) 事件(event) .net core 2.0 event bus 一个简单的基于内存事件总线实现 .net core 基于NPOI 的excel导出类,支持自定义导出哪些字段 基于Ace Admin 的菜单栏实现 第五节:SignalR大杂烩(与MVC融合、全局的几个配置、跨域的应用、C/S程序充当Client和Server)
并发编程概述 前言 说实话,在我软件开发的头两年几乎不考虑并发编程,请求与响应把业务逻辑尽快完成一个星期的任务能两天完成绝不拖三天(剩下时间各种浪),根本不会考虑性能问题(能接受范围内).但随着工 ...
- .NET Core的响应式框架,基于Ace Admin框架菜单导航,Bootstrap布局,fontAwesome图标,内嵌Iframe用EasyUI做数据绑定,动态配置列表,动态配置表单
netnrf 响应式框架 用于快速开发的响应式框架 演示:https://rf2.netnr.com v3.x 前端采用 jQuery + Bootstrap + EasyUI + AceAdmin ...
- YII与Ace Admin 的集成
目录 一. 前言... 1 二.为什么要使用YII+ace. 1 三.新建YII模块... 1 四.如何修改模板... 3 五.注意的地方... 4 六.整合的不足之处... 4 一. 前言 yii- ...
- Ace Admin 使用教程
(原) 公司项目要换框架,然后丢了一套国外的给我,ace admin,本想着拿来改改,翻翻百度就能用的,可它是国外的啊,国内普及率又不高,没办法,硬着头皮一点点啃英文文档吧. File(文件) 简介: ...
- 改造 Ace Admin 模板的 ace_tree 组件的 folderSelect 样式
*注:我用的Ace Admin版本为1.3.4 Ace Admin 是一个轻量,功能丰富,HTML5.响应式.支持手机及平板电脑上浏览的优秀管理后台模板. 关于tree的使用,html文件夹下tree ...
- Ace admin 如何实现类似于freamset加载页面
如上标题所述,ace admin做后台页面的时候,可以实现类似于用freamset的功能,但是ace admin做的比freamset更好,他可以用异步加载的形式展示,而加载的页面的内容可以尽可能的少 ...
- ace admin 左侧菜单定位
后台模版来自:Ace Admin http://ace.jeka.by/form-elements.html 左侧菜单,通过js根据url来判断显示哪块 window.location.pathnam ...
- c++ 跨平台线程同步对象那些事儿——基于 ace
前言 ACE (Adaptive Communication Environment) 是早年间很火的一个 c++ 开源通讯框架,当时 c++ 的库比较少,以至于谈 c++ 网络通讯就绕不开 ACE, ...
- 基于ACE的c++线程封装
1. 基本需求 1) 一个基类,其某个方法代表一个线程的生命运行周期.之后通过继承自这个基类来实现个性化线程类: 2) 具备类似QObject的定时器设置功能: 3) 提供在线程对象中同步和异步执行方 ...
随机推荐
- BZOJ4198:[NOI2015]荷马史诗
浅谈\(Huffman\)树:https://www.cnblogs.com/AKMer/p/10300870.html 题目传送门:https://lydsy.com/JudgeOnline/pro ...
- BMP格式转JPEG格式
int Bmp2Jpg(const char *bmp_data, const char *jeg_file, const int width, const int height) { int ret ...
- 蓝桥杯 历届试题 PREV-33 兰顿蚂蚁
历届试题 兰顿蚂蚁 时间限制:1.0s 内存限制:256.0MB 问题描述 兰顿蚂蚁,是于1986年,由克里斯·兰顿提出来的,属于细胞自动机的一种. 平面上的正方形格子被填上黑色或白色.在其中 ...
- 机器学习:调整kNN的超参数
一.评测标准 模型的测评标准:分类的准确度(accuracy): 预测准确度 = 预测成功的样本个数/预测数据集样本总数: 二.超参数 超参数:运行机器学习算法前需要指定的参数: kNN算法中的超参数 ...
- 【转】 Pro Android学习笔记(八一):服务(6):复杂数据Parcel
目录(?)[-] 自定义的Parcelable类 AIDL文件 服务的实现 Client的实现 同步和异步 文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处 ...
- eclipse中删除tomcat server 导致不能重新创建该server
定位到:workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings 1 打开org.eclipse.jst.server.tomca ...
- Mycat-server-1.6.5 常见分片方式
Mycat-server-1.6.5 常见分片方式 1 安装 [root@hongquan1 soft]# tar zxvf Mycat-server-1.6.5-release-2018012222 ...
- spring--AOP--日志---demo1---bai
AOP日志DEMO1: 实体类: package com.etc.entity; import org.aspectj.lang.annotation.Pointcut; public class U ...
- json例子--bai
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- paramiko监控 windows服务器 被监控服务器只需要安装openssh服务即可基于wmic完成大部分监控
#!/usr/bin/python #-*- coding: UTF-8 -*- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...