1 主方法:
if (perlist != null && perlist.Count > 0) { foreach(AuthPermission per in perlist) { if (per.parentId == 0) { sbStr.Append( per.mName + ",sun("); getSunPermission(perlist, per.menuId, sbStr); sbStr.Append(")"); } } }
2 递归
/// <summary> /// 递归获取子菜单 /// </summary> /// <param name="perList"></param> /// <param name="thisMenuId"></param> /// <returns></returns> public void getSunPermission(IList<AuthPermission> perList, int thisMenuId, StringBuilder menuStr) { IList<AuthPermission> sunlist = (from per in perList where per.parentId == thisMenuId select per).Reverse<AuthPermission>().ToArray(); if (sunlist == null || sunlist.Count <= 0) { return ; } else { foreach (AuthPermission per in sunlist) { menuStr.Append(""+per.mName+","); getSunPermission(perList, per.menuId, menuStr); } } }