var setting = { async: { enable: true, url: "*****/LoadChild", autoParam: ["id"], dataFilter: filter } }; function filter(treeId, parentNode, childNodes) { if (!childNodes) return null; for (var i = 0, l = childNodes.length; i < l; i++) { childNodes[i].name = childNodes[i].name.replace(/.n/g, '.'); } return childNodes; }
后台
public ActionResult LoadChild(string id) { List<Sys_User_List> listUser = _bll.GetList(id, false);//得到子节点 var list = listUser.Select(user => { var treeNode = new ZTreeJsonEntityForGrant { id = user.Id.ToString(), pId = id, name = user.User_Name, isHidden = false, isDisable = false, open = false, type = "User", drag = true }; if (treeNode.isDisable) { treeNode.icon = staticFile + "/Content/Images/Icon16/user_silhouette.png"; } else { treeNode.icon = (!string.IsNullOrEmpty(user.Gender) && user.Gender.Equals("女") == true) ? staticFile + "/Content/Images/Icon16/user_female.png" : staticFile + "/Content/Images/Icon16/user.png"; } return treeNode; }).ToList(); return new ConfigurableJsonResult<ZTreeJsonEntityForGrant>(list); }
public class ZTreeJsonEntityForGrant { /// <summary> /// 节点父ID /// </summary> public string pId { get; set; } /// <summary> /// 节点ID /// </summary> public string id { get; set; } /// <summary> /// 节点显示内容 /// </summary> public string name { get; set; } /// <summary> /// 是否展开 /// </summary> public bool open { get; set; } /// <summary> /// 是否可以拖拽 /// </summary> public bool drag { get; set; } /// <summary> /// 是否父节点 /// </summary> public bool isParent { get; set; } /// <summary> /// 节点图标 /// </summary> public string icon { get; set; } /// <summary> /// 是否隐藏 /// </summary> public bool isHidden { get; set; } /// <summary> /// 是否禁用 /// </summary> public bool isDisable { get; set; } public string type { get; set; } }