主攻ASP.NET.4.5.1 MVC5.0之重生:在项目中使用zTree jQuery 树插件
效果图和json格式
Controllers代码
using HR.Models;
using HR.Models.Repository;
/************************************************************************************
* 命名空间:HR.Controllers
* Controller: TreeController
* 版本号: F 1.0.0.0
* 负责人: Markfan
* 电子邮箱:ffgign@qq.com
* 移动电话:159 2760 2711
* QQ号码: 115637488
* 代码说明:全部类型树菜单
*
*
* =====================================================================
* 更新记录
* 更新人:
* 版本号: F 1.0.0.0
* 更新代码说明:
*
************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HR.ViewModels;
using HR.Helpers; namespace HR.Controllers
{ public class TreeController : Controller
{
//
// GET: /Tree/
DepartmentRepository departrepository = new DepartmentRepository();
ClassRepository classrepository = new ClassRepository();
SystemUserRepository systemuserrepository = new SystemUserRepository();
public IQueryable<Department> list { set; get; }
public ActionResult Index()
{
string cookie = CookieHelper.GetValue("SystemUserID");
int sid = int.Parse(CookieHelper.GetValue("SystemUserID"));
var model = systemuserrepository.GetModel(sid);
Employees em = new Employees();
if (model != null)
{
em = emprep.GetModelList().Where(d => d.WorkNumber == model.LogName).FirstOrDefault();
}
if (em != null)
{
ViewBag.empid = em.DepartmentID;
} return View();
} public ActionResult Show()
{
return View();
} //显示部门
public JsonResult TreeShow()
{
//查询顶级部门列表
var parentdepartmentlist = departrepository.GetModelListByState()
.Where(d => d.ParentID == )
.OrderBy(d => d.Sort);
//查询岗位列表
var joblist = classrepository.GetModelListByState().Where(d => d.ParentID == );
var treelist = new List<DepartViewModel>(); foreach (var parentdepartment in parentdepartmentlist)
{
var parentdepartmentmodel = new DepartViewModel();
parentdepartmentmodel.id = parentdepartment.DepartmentID.ToString();
parentdepartmentmodel.name = parentdepartment.DepartmentName;
parentdepartmentmodel.open = "true";
parentdepartmentmodel.pId = "";
parentdepartmentmodel.click = "AddDepartment(" + parentdepartment.DepartmentID + ",'" + parentdepartment.DepartmentName + "');";
treelist.Add(parentdepartmentmodel);
var departmentlist = departrepository.GetModelListByState()
.Where(d => d.ParentID == parentdepartment.DepartmentID)
.OrderBy(d => d.Sort);
foreach (var deparment in departmentlist)
{
var deparmentmodel = new DepartViewModel();
deparmentmodel.id = deparment.DepartmentID.ToString();
deparmentmodel.name = deparment.DepartmentName;
deparmentmodel.open = "false";
deparmentmodel.pId = deparment.ParentID.ToString();
deparmentmodel.click = "AddDepartment(" + deparment.DepartmentID + ",'" + deparment.DepartmentName + "');";
treelist.Add(deparmentmodel);
}
} var source = from c in treelist
select c;
return Json(source, JsonRequestBehavior.AllowGet);
}
EmployeesRepository emprep = new EmployeesRepository();
public JsonResult Tree()
{ var parentdepartmentlist = departrepository.GetModelListByState()
.Where(d => d.ParentID == )
.OrderBy(d => d.Sort);
var joblist = classrepository.GetModelListByState().
Where(d => d.ParentID == )
.OrderBy(d => d.Sort);
var treelist = new List<DepartViewModel>(); foreach (var parentdepartment in parentdepartmentlist)
{
var parentdepartmentmodel = new DepartViewModel();
parentdepartmentmodel.id = parentdepartment.DepartmentID.ToString();
parentdepartmentmodel.name = parentdepartment.DepartmentName;
parentdepartmentmodel.open = "false";
parentdepartmentmodel.pId = "";
parentdepartmentmodel.url = "/employees/index/0?Jobs=0";
parentdepartmentmodel.target = "rform";
treelist.Add(parentdepartmentmodel); var departmentlist = departrepository.GetModelListByState()
.Where(d => d.ParentID == parentdepartment.DepartmentID)
.OrderBy(d => d.Sort);
foreach (var deparment in departmentlist)
{
var deparmentmodel = new DepartViewModel();
deparmentmodel.id = deparment.DepartmentID.ToString();
deparmentmodel.name = deparment.DepartmentName;
deparmentmodel.open = "false";
deparmentmodel.pId = deparment.ParentID.ToString();
deparmentmodel.url = "/employees/index/" + deparment.DepartmentID + "?Jobs=0";
deparmentmodel.target = "rform";
treelist.Add(deparmentmodel);
foreach (var job in joblist)
{
var model = new DepartViewModel();
model.id = deparment.DepartmentID.ToString() + "-" + job.ClassID.ToString();
model.name = job.ClassName;
model.pId = deparment.DepartmentID.ToString();
model.open = "false";
model.url = "/employees/index/" + deparment.DepartmentID + "?Jobs=" + job.ClassID + "";
model.target = "rform";
treelist.Add(model);
}
} } var source = from c in treelist
select c;
return Json(source, JsonRequestBehavior.AllowGet);
}
public JsonResult TreeType(int id)
{
string cookie = CookieHelper.GetValue("SystemUserID"); if (string.IsNullOrEmpty(cookie))
{
int sid = int.Parse(CookieHelper.GetValue("SystemUserID"));
var model = emprep.GetModel(sid);
Employees em = new Employees();
if (model != null)
{
var emp = emprep.GetModelList().Where(d => d.WorkNumber == model.WorkNumber).FirstOrDefault();
}
ViewBag.empid = em.DepartmentID;
} var parentdepartmentlist = departrepository.GetModelListByState()
.Where(d => d.ParentID == )
.OrderBy(d => d.Sort);
var joblist = classrepository.GetModelListByState().
Where(d => d.ParentID == )
.OrderBy(d => d.Sort);
var treelist = new List<DepartViewModel>(); foreach (var parentdepartment in parentdepartmentlist)
{
var parentdepartmentmodel = new DepartViewModel();
parentdepartmentmodel.id = parentdepartment.DepartmentID.ToString();
parentdepartmentmodel.name = parentdepartment.DepartmentName;
parentdepartmentmodel.open = "false";
parentdepartmentmodel.pId = "";
parentdepartmentmodel.url = "/employees/index/0?Jobs=0";
parentdepartmentmodel.target = "rform";
treelist.Add(parentdepartmentmodel); var departmentlist = departrepository.GetModelListByState()
.Where(d => d.DepartmentID == id)
.OrderBy(d => d.Sort);
foreach (var deparment in departmentlist)
{
var deparmentmodel = new DepartViewModel();
deparmentmodel.id = deparment.DepartmentID.ToString();
deparmentmodel.name = deparment.DepartmentName;
deparmentmodel.open = "false";
deparmentmodel.pId = deparment.ParentID.ToString();
deparmentmodel.url = "/employees/index/" + deparment.DepartmentID + "?Jobs=0";
deparmentmodel.target = "rform";
treelist.Add(deparmentmodel);
foreach (var job in joblist)
{
var model = new DepartViewModel();
model.id = deparment.DepartmentID.ToString() + "-" + job.ClassID.ToString();
model.name = job.ClassName;
model.pId = deparment.DepartmentID.ToString();
model.open = "false";
model.url = "/employees/index/" + deparment.DepartmentID + "?Jobs=" + job.ClassID + "";
model.target = "rform";
treelist.Add(model);
}
} } var source = from c in treelist
select c;
return Json(source, JsonRequestBehavior.AllowGet);
}
}
}
using HR.Models;
using HR.Models.Repository;
/************************************************************************************
* CLR版本: 4.0.30319.18051
* 机器名称:MARKFAN
* 命名空间:HR.ViewModels
* 文件名: DepartViewModel
* 版本号: V1.0.0.0
* 唯一标识:cfcc84df-4cea-4400-9e02-95ba620a453d
* 创建人: Markfan * 电子邮箱:ffgign@qq.com
* 移动电话:159 2760 2711
* QQ号码: 115637488
* 创建时间:2014/05/12 20:51:56
* 描述:
*
*
* =====================================================================
* 修改标记
* 修改时间:2014/05/12 21:20:13
* 修改人: mark
* 版本号: F1.0.0.0
* 描述:
*
*
*
*
************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace HR.ViewModels
{
public class DepartViewModel
{
/// <summary>
/// ID
/// </summary>
public string id { get; set; }
/// <summary>
/// 父级ID
/// </summary>
public string pId { get; set; }
/// <summary>
/// 名称
/// </summary>
public string name { get; set; }
/// <summary>
/// 是否展开
/// </summary>
public string open { get; set; }
/// <summary>
/// 跳转地址
/// </summary>
public string url { get; set; }
/// <summary>
/// 跳转属性
/// </summary>
public string target { get; set; }
/// <summary>
/// 点击事件
/// </summary>
public string click { get; set; }
}
}
页面调用代码
@{
ViewBag.Title = "Index";
} <!DOCTYPE html>
<html>
<head>
<title>tree</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script src="~/Content/EasyUI/jquery-1.8.3.min.js"></script>
<link href="~/Content/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
<script src="~/Content/js/jquery.ztree.core-3.5.js"></script> <script type="text/javascript">
<!--
var setting = {
data: {
simpleData: {
enable: true
}
}
};
var url = "/Tree/Tree";
// var url = "/Tree/TreeType/@ViewBag.empid";
$.get(url, function (data) {
$.fn.zTree.init($("#treeDemo"), setting, data);
});
//-->
</script>
<style type="text/css">
</style>
</head> <body>
<div class="content_wrap">
<div class="zTreeDemoBackground left">
<ul id="treeDemo" class="ztree"></ul>
</div>
</div>
</body>
</html>
下载ztree地址: http://www.ztree.me/
声明:本博客高度重视知识产权保护,发现本博客发布的信息包含有侵犯其著作权的链接内容时,请联系我,我将第一时间做相应处理,联系邮箱ffgign@qq.com。
作者:Mark Fan (小念头) 来源:http://cube.cnblogs.com
说明:未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。如有疑问,可以通过 ffgign@qq.com 联系作者,本文章采用 知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可
主攻ASP.NET.4.5.1 MVC5.0之重生:在项目中使用zTree jQuery 树插件的更多相关文章
- 主攻ASP.NET.4.5.1 MVC5.0之重生:Web项目语音朗读网页文本,简单语音提示浏览状态
第一步 添加SpeechLib.dll 下载SpeechLib.dll: 在项目中并且引用DLL using SpeechLib; using System.Threading; 第二步 调用并使用 ...
- 主攻ASP.NET.4.5.1 MVC5.0之重生:系统角色与权限(一)
数据结构 权限分配 1.在项目中新建文件夹Helpers 2.在HR.Helpers文件夹下添加EnumMoudle.Cs namespace HR.Helpers { public enum Enu ...
- 主攻ASP.NET.4.5.1 MVC5.0之重生:空地搭建一个包含 Ninject框架 项目
1.创建一个空白解决方案 2.添加一个类库 名称为XXX.Domain 3.添加一个ASP.MVC 名称为XXX.WebUI 4.选着空模版,勾选MVC核心引用 5.添加单元测试项目XXX.UntiT ...
- 主攻ASP.NET.4.5.1 MVC5.0之重生:政府行政网站常用友情链接跳转javascript[干货分享]
<!-----------------------------------> <script language="JavaScript" type="t ...
- 主攻ASP.NET.4.5.1 MVC5.0之重生:创建UIHelper通用自定义分页和选择开关与PagesHelper和IsSelect简单用法
@helper放入地方 分页效果 选择开关编辑调用 <dl> <dd class="dc1">是否主管:</dd> <dd> @UI ...
- 主攻ASP.NET.4.5.1 MVC5.0之重生:系统角色与权限(二)
系统角色篇 数据结构 用户管理 Controller代码 public class SystemUserController : Controller { //public void Log() // ...
- 主攻ASP.NET.4.5.1 MVC5.0之重生:根据产品类别显示菜单分类和分页
路径访问的几种方式和分页效果 显示其它类别的效果和多数据分页效果 默认访问网站路径效果和多数据分页效果 URL路径访问可页面 http://localhost:5339/stationery http ...
- spring3.0结合Redis在项目中的运用
推荐一个程序员的论坛网站:http://ourcoders.com/home/ 以下内容使用到的技术有:Redis缓存.SpringMVC.Maven.项目中使用了redis缓存,目的是在业务场景中, ...
- 无法安装程序包“MIcrosoft.Owin.Security 2.0.2”。您正在尝试将此程序包安装到某个将“.NETFramework,Version=v4.0”作为目标的项目中。
在VS2010 MVC4项目中,安装NuGet程序包Microsoft.AspNet.SignalR时出现以下错误: 原因是安装的版本是Microsoft.AspNet.SignalR 2.0.2,要 ...
随机推荐
- python 循环内部添加多个条件判断会出现越界
1.循环遍历数组是,想添加条件修改时,只删除第一个 # -*- coding: utf-8 -*- a=[11,22,33,44,55] for i in a: if i == 11 or i ==2 ...
- 嵌入式开发之davinci--- 8148/8168/8127 中swms、Mosaic’s、display 显示pal 模式
(1) (2) (3) (4) -------------------------author:pkf ------------------------------time:2-3 --------- ...
- android studio win7开发环境
java 开发环境 这里使用jdk1.7版本,从官网上下载. 点击.正常的window软件的安装方式,一直下一步即可. 环境变量的设置: 在系统属性中,对需要的环境变量进行设置: JAVA_HOME设 ...
- WPF TextBox 验证输入
//验证输入为数字private void txt_time_KeyDown(object sender, KeyEventArgs e){ if (!((e.Key >= Key.D0 &am ...
- 如何获取继承中泛型T的类型
@SuppressWarnings("unchecked") public void testT() { clazz = (Class<T>)( (Parameteri ...
- 头一次玩博客,记录下我的java之路吧
今天写了简单的后台管理系统,发现光靠脑子记住知识真的很难,笔记本不好翻,之前写的代码更难找,所以写写博客,记录一些知识,为了以后上班用得到.
- 32位Win7下安装与配置PHP环境(一)
运行PHP网站,主要需要安装.配置三个软件,Apache.PHP和MySQL.如果需要编辑调试PHP程序,还要安装一个编辑调试软件. 一. Apache Apache是和IIS类似的一个软件,是运行在 ...
- Unique Encryption Keys
The security of many ciphers strongly depends on the fact that the keys are unique and never re-used ...
- php5.4新特性实践
本机安装的是wampserver2.2e-php5.4.3-httpd2.2.22-mysql5.5.24-32b.exe集成包 自带了php5.4 1. 数组写法 定义一个数组 过去: $arr = ...
- JS HTML DOM---Document对象
Document 对象 当浏览器载入 HTML 文档, 它就会成为 document 对象. document 对象是HTML文档的根节点与所有其他节点(元素节点,文本节点,属性节点, 注释节点). ...