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. ...
随机推荐
- Oracle Essbase入门系列(二)
本篇开始会一个三口之家的家庭财务数据库为例,讲述Essbase的功能和开发.为了说明EPM应用程序的管理和开发过程,会绕一些弯路,不使用EAS,而尽量用EPMA. 创建应用程序 首先登陆到Worksp ...
- Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题
C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...
- window下,加载redis拓展
下载地址: http://windows.php.net/downloads/pecl/snaps/redis/2.2.5/ 看下自己phpinfo的信息 就选择 ts-x86 ...
- How To Create a Personal Balance Sheet
Calculating your personal net worth is the best way to know exactly what your starting point is, in ...
- 使用PuTTY时的文件上传下载方法
如果你是个PuTTY重度用户,在使用ssh连上一个远端机器工作了好一阵子后,发现自己需要对 当前会话 上传/下载文件,要怎样才能简单快捷呢? 最简单的方式 最简单的方法: 安装WinSCP或者File ...
- juniper 550M訪问自身公网IP回流内部IP
拓扑图示意: 网关设备juniper 550M, untrust 区: 公网地址段22.22.22.22/29 trust区: 内部员工PC地址:172.16.4.x /24 trust区: ...
- java对过反射调用方法
public class InvokeTester { public InvokeTester() { } String str; public InvokeTester(String str) ...
- 聊聊并发(七)——Java中的阻塞队列
3. 阻塞队列的实现原理 聊聊并发(七)--Java中的阻塞队列 作者 方腾飞 发布于 2013年12月18日 | ArchSummit全球架构师峰会(北京站)2016年12月02-03日举办,了解更 ...
- 【学】常用hash算法的介绍
基本知识 Hash,一般翻译做“散列”,也有直接音译为“哈希”的,就是把任意长度的输入(又叫做预映射, pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值.这种转换是一种压缩映 ...
- JS移动端滑屏事件
来看看在pc上面的几个事件:onmousedown,onmousemove,onmouseup 我相信大家对这几个事件一定不陌生,第一个onmousedown表示鼠标按下,第二个onmousemove ...