1.SMSInfo_Add页面初始化部门人员并缓存起来
1 $(function () { 2 createInternalUsers(""); 3 createExternalUsers(); 4 $.post("Action.ashx?t=GetUserTree", function () { })//预加载部门人员,缓存后直接调用 5 });
2.Internalusers页面调用初始化的部门人员
1 //部门人员树形节点 2 function createTree() { 3 $.ajax({ 4 url: 'Action.ashx?t=GetUserTree', 5 data: { id: "100" }, 6 type: 'POST', 7 dataType: "json", 8 success: function (result) { 9 if (result.success) { 10 $("#dtload").hide(); 11 zNodes = result.data; 12 zTree = $.fn.zTree.init($("#treeUser"), setting, zNodes); 13 zTree.addNodes(null, 0, { id: '00F157EB-1D3A-45FD-AF42-5B142C8D5EHX', pId: 'companyall', isParent: false, name: "公司全员" }); 14 var guId = "<%=ReceiveDeptGUID2 %>"; //$("#hid").val(); 15 guId = guId.substring(1, guId.length - 1); 16 var idStr = guId.split(','); 17 for (var i = 0; i < idStr.length; i++) { 18 //alert(idStr[i]); 19 zTree.checkNode(zTree.getNodeByParam("id", $.trim(idStr[i])), true, true); 20 GetNodes(); 21 } 22 } else { 23 $("#dtload").hide(); 24 $("#treeUser").html("<li class='red'>服务器异常:获取用户失败</li>"); 25 } 26 } 27 }); 28 }
3.部门人员方法
1 public string GetUserTree(HttpContext context) 2 { 3 string json = ""; 4 try 5 { 6 if (context.Cache["usertree"] == null) 7 { 8 SYSUser sysUser = context.Session["SYSUser"] as SYSUser; 9 DepartmentInfo[] dept = port.GetAllDept(); 10 GetNodeDeptUser(dept, sysUser.CPInnerID); 11 context.Cache.Insert("usertree", nlist, null, DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration); 12 } 13 else { 14 nlist = (List<zTreeNode>)context.Cache["usertree"]; 15 } 16 var obj = new { success = true, data = nlist, msg = "" }; 17 json = HX.Common.JsonHelper.SerializeObject(obj); 18 } 19 catch (Exception ex) 20 { 21 var obj = new { success = false, msg = ex.Message }; 22 json = HX.Common.JsonHelper.SerializeObject(obj); 23 } 24 return json; 25 }