EasyUI组合树插件
一、引用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'); // 获得树对象
|
| 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组合树插件的更多相关文章
- 表单(上)EasyUI Form 表单、EasyUI Validatebox 验证框、EasyUI Combobox 组合框、EasyUI Combo 组合、EasyUI Combotree 组合树
EasyUI Form 表单 通过 $.fn.form.defaults 重写默认的 defaults. 表单(form)提供多种方法来执行带有表单字段的动作,比如 ajax 提交.加载.清除,等等. ...
- easyui&8Jquery ztree树插件
7Jquery easyui前台UI框架 开发包: 7.1Layout页面布局 将课后资料中后台系统前台页面素材导入项目中 1.导入Jquery,easyui相关js,css文件 <link r ...
- 基于MVC4+EasyUI的Web开发框架经验总结(2)- 使用EasyUI的树控件构建Web界面
最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开发框架保持一致,而在Web上,我主要采用EasyUI的前端界面处理技术,走MVC的技术路线,在重 ...
- Jquery UI 组合树 - ComboTree 集成Wabacus4.1 代码剖析
Jquery UI 1.3 (组合树 - ComboTree ) 集成Wabacus4.1 集成Spring 代码剖析 使用时,请下载需要Jquery ui包进行配置 combotree.js 的代码 ...
- 使用EasyUI的树控件构建Web界面
最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开发框架保持一致,而在Web上,我主要采用EasyUI的前端界面处理技术,走MVC的技术路线,在重 ...
- ASP.NET MVC jQuery 树插件在项目中使用方法(一)
jsTree是一个 基于jQuery的Tree控件.支持XML,JSON,Html三种数据源.提供创建,重命名,移动,删除,拖"放节点操作.可以自己自定义创建,删 除,嵌套,重命名,选择节点 ...
- Unity火爆插件Behavior Designer行为树插件学习
如果要让游戏里的角色或者NPC能执行预设的AI逻辑,最简单的用IF..ELSE...神器既可以实现, 但是再复杂的一般用经典的状态机来切换状态,但是写起来比较麻烦.相对的,行为树(Behavior T ...
- combotree(组合树)的使用
一.前言: 组合树(combotree)把选择控件和下拉树结合起来.它与组合框(combobox)相似,不同的是把列表替换成树组件.组合树(combotree)支持带有用于多选的树状态复选框的树. 二 ...
- js组件在线编辑器插件、图表库插件、文件树插件
在线编辑器插件: 一.kindeditor 二.UEditor 图表库插件: 一.echart 二.highchart 文件树插件: 一.zTree -- jQuery 树插件 http://www. ...
随机推荐
- 前端测试回顾及我们为什么选择Karma
前端测试,或者UI测试一直是业界一大难题.最近Q.js使用Karma作为测试任务管理工具,本文在回顾前端测试方案的同时,也分析下为什么Q.js选用Karma而不是其他测试框架. 像素级全站对比 曾今有 ...
- Hadoop 2.7.1 源代码目录结构分析
采用的源代码是2.7.1的,从这个网站下可以找到2.7.1的代码:https://git1-us-west.apache.org/ ,使用gitclone出来,然后git checkout到2.7.1 ...
- Python的Descriptor和Property混用
一句话,把Property和Descriptor作用在同一个名字上,就只有Property好使.
- Hadoop - Zeppelin 使用心得
1.概述 在编写 Flink,Spark,Hive 等相关作业时,要是能快速的将我们所编写的作业能可视化在我们面前,是件让人兴奋的时,如果能带上趋势功能就更好了.今天,给大家介绍这么一款工具.它就能满 ...
- UE4在Android调用Project Tango
Project Tango应该说是Google一试水AR的设备,其中Project Tango主要二个功能,一个是获取深度信息,如MS的Kinect,有相当多的设备都有这个功能,二是第一人称相对定位, ...
- [原]cocos2d-lua 常用法汇总
1.CCEditBox local back = CCScale9Sprite:create("res/ui/images/im_02.png", CCRect(20, 20, 1 ...
- 程序员之路:以Android证道
大道三千,何以证道? 最近有私信.邮件给我咨询一些职业生涯规划的同学,我在这里以过来人的身份给大家一些建议. 任何行业,任何职位,无论高低,无论大小,都可以分为广博.精深两个方向. 精深自然指的是在某 ...
- iOS开发之时间格式的转化
在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理. 例如:如何将格式为“12-May-14 05.08.02.000000 PM” ...
- cordova 学习笔记
0.sdk安装 http://spring.io/guides/gs/android/ 1.安装(node.js 需要安装https://nodejs.org/) on OS X and Linux: ...
- python 字符串查找
python 字符串查找有4个方法,1 find,2 index方法,3 rfind方法,4 rindex方法. 1 find()方法: )##从下标1开始,查找在字符串里第一个出现的子串:返回结果3 ...