<p>
前端页面js:就是这么简单暴力
///获取combotree的方法
function GetTree() { $("#tree").combotree({width: 175,
url: '/OrganizationManager/Permission/GetTree', valueField: 'id', textField: 'text', editable: false });}
控制器以及数据访问层:
public JsonResult GetTree()
{string parentNodeId = Request["id"] ?? null;//easyui 会每展开一个节点,往后端传一个·id
if (string.IsNullOrEmpty(parentNodeId))
{ parentNodeId = "0"; } List<Model.RunUI.TreeModule> Toptree = bllper.GetSubNodes(parentNodeId);return Json(Toptree, JsonRequestBehavior.AllowGet);
}
/// <summary>
/// * 获取菜单的树的方法* /// </summary> /// <param name="parentNodeId"></param> /// <returns></returns> public List<Model.RunUI.TreeModule> GetSubNodes(string parentNodeId) { string sql = "select * from Per_Module "; DataTable dt = DbHelperSQL.Query(sql).Tables[0]; List<Model.RunUI.TreeModule> Tree = new List<Model.RunUI.TreeModule>(); Model.RunUI.TreeModule TM = null; if (dt != null && dt.Rows.Count > 0) { DataRow[] rows = dt.Select("ParentModuleID ='" + parentNodeId + "'");foreach (DataRow item in rows)
{ string id = item["ModuleID"].ToString(); string text = item["Name"].ToString(); TM = new TreeModule();DataRow[] IsNulRows = dt.Select("ParentModuleID ='" + id + "'");
if (IsNulRows.Length > 0)
{ TM.state = "closed";//这个很关键,此节点为closed状态,才可以展开,才能往后台传你点击的id 看到Combotree的异步加载Demo,发现treegrid_data.json中 state="closed" 属性能把点击展开的节点Id传到后台中 }TM.id = id;
TM.text = text;Tree.Add(TM);
} } return Tree; }
model:类:
public class TreeModule {public string id { get; set; }
public string text { get; set; }
public string state { get; set; }
}就是这么简单暴力
</P>