效果图:
页面:
<div id="divs" style="width: 310px; overflow-x: hidden; overflow-y: hidden; border-radius: 10px; height: 420px; top: 80px; left: 520px; z-index: 100; position: absolute; border: 10px solid #FF5555; background-color: white;"> <table style="width: 100%; text-align: right;"> <tr> <td><span id="Span1" style="cursor: pointer;" onclick="clad()">确定</span> <span id="gb" style="cursor: pointer; margin-right: 5px">关闭</span> </td> </tr> </table> <div style="width: 300px; height: 400px; margin-top: 0px; float: left; overflow-x: hidden; overflow-y: auto; border: 1px solid #ccc;"> <ul id="tree1"> </ul> </div> </div>
js
$(function () { $("#divs").hide(); //t = $("#tree1").ligerTree({ checkbox: true }); $("#gb").click(function () { $("#divs").hide(); }); $("#TextBox2").ligerTextBox({ width: 500 }); $("#tree1").ligerTree({ nodeWidth: 300, url: ‘gongwenHandler.ashx?bz=tree&type=company‘, checkbox: true, idFieldName: ‘id‘, parentIDFieldName :‘pid‘, slide: false }); manager = $("#tree1").ligerGetTreeManager(); }); function clad() { var notes = manager.getChecked(); var text = ""; for (var i = 0; i < notes.length; i++) { if (notes[i].data.isparent == ‘2‘) { var users = $("#hdToUsers").val() + notes[i].data.id + ‘,‘ $("#hdToUsers").val(users); text += notes[i].data.text + " "; } } $("#TextBox2").val(text); $("#divs").hide(); } function showd() { $("#divs").show(); }
gongwenHandler.ashx 后台:
//加载公司,部门,人员树。 case "tree": string type = context.Request.Params["type"]; string prev = context.Request.Params["prev"]; List<TreeNode> list = new List<TreeNode>(); if (type == "company") { DataTable danwei = EDU.DBUtility.DbHelperSQL.GetDataTable("select orgId_I,orgName_N from Organize"); //遍历公司 foreach (DataRow row in danwei.Rows) { TreeNode node = new TreeNode(); node.id = Convert.ToString(row["orgId_I"]); node.pid = "0"; node.text = Convert.ToString(row["orgName_N"]); node.isparent = "0"; list.Add(node); //遍历出部门 DataTable depart = EDU.DBUtility.DbHelperSQL.GetDataTable("select ID,BuMenName from ERPBuMen where suoshudanwei=‘" + Convert.ToString(row["orgId_I"]) + "‘"); foreach (DataRow deptRow in depart.Rows) { TreeNode deptnode = new TreeNode(); deptnode.id = Convert.ToString(deptRow["ID"]); deptnode.pid = Convert.ToString(row["orgId_I"]); deptnode.text = Convert.ToString(deptRow["BuMenName"]); deptnode.isparent = "1"; list.Add(deptnode); //遍历员工 DataTable emp = EDU.DBUtility.DbHelperSQL.GetDataTable("select userId_I,firstName_N from Users where orgId_I=‘" + Convert.ToString(row["orgId_I"]) + "‘ and departId_I=‘" + Convert.ToString(deptRow["ID"]) + "‘"); foreach (DataRow empRow in emp.Rows) { TreeNode empnode = new TreeNode(); empnode.id = Convert.ToString(empRow["userId_I"]); empnode.pid = Convert.ToString(deptRow["ID"]); empnode.text = Convert.ToString(empRow["firstName_N"]); empnode.isparent = "2"; list.Add(empnode); } } } string strJson = LitJson.JsonMapper.ToJson(list); context.Response.ContentType = "text/plain"; context.Response.Write(strJson); context.Response.End(); } break;
public class TreeNode { public string id { get; set; } public string pid { get; set; } public string text { get; set; } public string isparent { get;set;} }
时间: 2024-10-02 02:08:21