一、引用CSS和JS

<link href="~js/easyui/easyui.css" rel="stylesheet" type="text/css" />
<script src="~js/easyui/jquery.easyui.min.js" type="text/javascript"></script>

二、HTML代码

<input type="text" id="subject" name="subject">

三、JS代码

$('#dept').combotree({
url: '#{GetDeptTree}',
required: false,
onSelect: function (node) {
$.ajax({
type: "POST",
url: "#{GetJobs}",
data: "deptId=" + node.id,
success: function (data) {
$("#job").html(data);
}
});
}
}); $('#dept').combotree('setValue', "#{employmentNeeds.Dept.Id}");
//部门员工树
$('#Employee').combotree({
url: '#{GetEmployees}',
required: false,
onSelect: function (node) {
//控制只能选叶子节点
//返回树对象
var tree = $(this).tree;
//选中的节点是否为叶子节点,如果不是叶子节点,清除选中
var isLeaf = tree('isLeaf', node.target);
if (!isLeaf) {
//清除选中
$('#Employee').combotree('clear');
return;
} //员工基本信息赋值
var att = eval("({" + node.attributes + "})");
$("#spanDeptName").html(att.DeptName);
$("#spanJobName").html(att.JobName);
$("#spanEmpCode").html(att.EmpCode);
$("#spanEntryTime").html(att.EntryTime);
}
});

三、后台代码:

/// <summary>
/// 获取员工(部门树和员工)
/// </summary>
public void GetEmployees()
{
echoJson(GetDepts(Constants.OptionAllVal, dropListService.GetDepts(LoginUser)));
} /// <summary>
/// 获取部门树
/// </summary>
private List<Dictionary<string, object>> GetDepts(int parentDeptId, List<IMP_Dept> allDeptList)
{
List<Dictionary<string, object>> dicList = new List<Dictionary<string, object>>(); List<IMP_Dept> deptList = allDeptList.FindAll(a => a.PId == parentDeptId);
if (deptList.Count == && parentDeptId != Constants.OptionAllVal) return null; foreach (IMP_Dept dept in deptList)
{
Dictionary<string, object> dic = new Dictionary<string, object>();
dic.Add("id", dept.Id);
dic.Add("text", dept.Name);
dic.Add("checkbox", true); List<Dictionary<string, object>> childDicList = new List<Dictionary<string, object>>(); //当前部门下的子部门
List<Dictionary<string, object>> childDeptDicList = GetDepts(dept.Id, allDeptList);
if (childDeptDicList != null)
{
childDicList.AddRange(childDeptDicList);
} //当前部门下的员工
List<Dictionary<string, object>> childEmployeeDicList = GetEmployees(dept);
if (childEmployeeDicList != null)
{
childDicList.AddRange(childEmployeeDicList);
} if (childDicList != null)
{
dic.Add("state", parentDeptId == Constants.OptionAllVal ? "open" : "closed");
dic.Add("children", childDicList);
} dicList.Add(dic);
} return dicList;
} /// <summary>
/// 获取部门下的员工
/// </summary>
private List<Dictionary<string, object>> GetEmployees(IMP_Dept dept)
{
List<Dictionary<string, object>> dicList = new List<Dictionary<string, object>>(); List<IMP_Employee> employeeList = employeeService.FindEmployeeDept(dept.Id);
if (employeeList.Count == ) return null; foreach (IMP_Employee employee in employeeList)
{
Dictionary<string, object> dic = new Dictionary<string, object>();
dic.Add("id", "emp" + employee.Id);
dic.Add("text", employee.Name);
dic.Add("checkbox", true);
string attributes = string.Format("'DeptName':'{0}','JobName':'{1}','EmpCode':'{2}','EntryTime':'{3}'",
employee.Dept == null ? "" : employee.Dept.Name,
employee.Job == null ? "" : employee.Job.Name,
employee.Code == null ? "" : employee.Code,
employee.EntryTime == DateTime.MinValue ? "" : employee.EntryTime.ToString(Constants.FormatDate));
dic.Add("attributes", attributes);
dicList.Add(dic);
} return dicList;
}

方法

扩展的方法继承于 combo,下面是添加和覆盖方法combotree.

名称 参数 说明
options none 返回选择对象。
tree none 返回对象的树。下面的例子显示了如何获得选中的树节点。

var t = $('#cc').combotree('tree');	// 获得树对象
var n = t.tree('getSelected'); // 获得选中节点显示(文本);
loadData data 加载本地组合树数据。代码示例:

$('#cc').combotree('loadData', [{id: 1,text: 'Languages',children: [{id: 11,text:'Java'},{id: 12,text: 'C++'}]}]);
reload url 再次请求远程树数据。通过“url”参数覆盖原始url值。
clear none 清除的组件值。
setValues values 设置组件值数组。代码示例:

$('#cc').combotree('setValues', [1,3,21]);
setValue value

设置组件的值。代码示例:

$('#cc').combotree('setValue', 6);

参考:http://blog.csdn.net/magister_feng/article/details/6619870

自定义属性:http://www.cnblogs.com/Nature-j/archive/2013/05/06/3062598.html

EasyUI组合树插件的更多相关文章

  1. 表单(上)EasyUI Form 表单、EasyUI Validatebox 验证框、EasyUI Combobox 组合框、EasyUI Combo 组合、EasyUI Combotree 组合树

    EasyUI Form 表单 通过 $.fn.form.defaults 重写默认的 defaults. 表单(form)提供多种方法来执行带有表单字段的动作,比如 ajax 提交.加载.清除,等等. ...

  2. easyui&8Jquery ztree树插件

    7Jquery easyui前台UI框架 开发包: 7.1Layout页面布局 将课后资料中后台系统前台页面素材导入项目中 1.导入Jquery,easyui相关js,css文件 <link r ...

  3. 基于MVC4+EasyUI的Web开发框架经验总结(2)- 使用EasyUI的树控件构建Web界面

    最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开发框架保持一致,而在Web上,我主要采用EasyUI的前端界面处理技术,走MVC的技术路线,在重 ...

  4. Jquery UI 组合树 - ComboTree 集成Wabacus4.1 代码剖析

    Jquery UI 1.3 (组合树 - ComboTree ) 集成Wabacus4.1 集成Spring 代码剖析 使用时,请下载需要Jquery ui包进行配置 combotree.js 的代码 ...

  5. 使用EasyUI的树控件构建Web界面

    最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开发框架保持一致,而在Web上,我主要采用EasyUI的前端界面处理技术,走MVC的技术路线,在重 ...

  6. ASP.NET MVC jQuery 树插件在项目中使用方法(一)

    jsTree是一个 基于jQuery的Tree控件.支持XML,JSON,Html三种数据源.提供创建,重命名,移动,删除,拖"放节点操作.可以自己自定义创建,删 除,嵌套,重命名,选择节点 ...

  7. Unity火爆插件Behavior Designer行为树插件学习

    如果要让游戏里的角色或者NPC能执行预设的AI逻辑,最简单的用IF..ELSE...神器既可以实现, 但是再复杂的一般用经典的状态机来切换状态,但是写起来比较麻烦.相对的,行为树(Behavior T ...

  8. combotree(组合树)的使用

    一.前言: 组合树(combotree)把选择控件和下拉树结合起来.它与组合框(combobox)相似,不同的是把列表替换成树组件.组合树(combotree)支持带有用于多选的树状态复选框的树. 二 ...

  9. js组件在线编辑器插件、图表库插件、文件树插件

    在线编辑器插件: 一.kindeditor 二.UEditor 图表库插件: 一.echart 二.highchart 文件树插件: 一.zTree -- jQuery 树插件 http://www. ...

随机推荐

  1. ajax 异步请求webservice(XML格式)

    function callAjaxWebservice(){ alert("call ajax"); try { $.ajax({ type: "POST", ...

  2. tensorflow 运行成功!

    折腾了一天安装tensorflow环境,终于可以运行,也记录一下安装中容易犯的错误总结(写给python小白们) 一.win7 双系统 安装ubuntu 16.04 ,参考 http://jingya ...

  3. 条件注释判断IE浏览器

    最近在用jquery 2.0 才知道已不支持IE6/7/8 但又不想换回 jquery 1.X; 找了一资料发现条件注释可以解决这个问题 这个也像程序中的条件判断,先来介绍几个单词lt :Less t ...

  4. 哈希表用于Key与Value的对应

    一个类的某个属性要实现Key与Value的对应,以便通过访问名称就可以知道对应值,而不是通过索引号,最简单的方法直接用 哈希表using System.Collections;class Class1 ...

  5. CentOS 7 Vmware虚拟机 /root空间不足解决方法(使用gparted live)

    1,关闭虚拟机,编辑虚拟机设置,增加虚拟磁盘的大小,我这里增加10GB 2,连接CDrom到ISO文件(gparted-live-0.19.0-1-i486.iso),使用gparted live启动 ...

  6. (OSP)外包工单关工单失败

    会计同事反映,在关几个外包(OSP)工单时,系统报错.错误讯息如下.检查错误讯息,发现Number of jobs failed in Delivered Quantity : 2.检查工单数据,均无 ...

  7. #ifdef 和 #if defined 的区别 -- 转

    #ifdef 和 #if defined 的区别在于,后者可以组成复杂的预编译条件,比如 #if defined (AAA) && defined (BBB) xxxxxxxxx #e ...

  8. [转]GeoHash核心原理解析

    原文出处: zhanlijun    引子 机机是个好动又好学的孩子,平日里就喜欢拿着手机地图点点按按来查询一些好玩的东西.某一天机机到北海公园游玩,肚肚饿了,于是乎打开手机地图,搜索北海公园附近的餐 ...

  9. [转载]QString 乱谈(3)-Qt5与中文

    原文地址http://blog.csdn.net/dbzhang800/article/details/7542672?reload 两个月前,简单写过QTextCodec中的setCodecForT ...

  10. CSS布局:Float布局过程与老生常谈的三栏布局

    原文见博客主站,欢迎大家去评论. 使用CSS布局网页,那是前端的基本功了,什么两栏布局,三栏布局,那也是前端面试的基本题了.一般来说,可以使用CSSposition属性进行布局,或者使用CSSfloa ...