/// <summary>
/// 提供给 easyui tree 使用的TreeNode类
/// </summary>
public class EasyTreeNode
{
public EasyTreeNode()
{
attributes = new Dictionary<string, string>();
children = new List<EasyTreeNode>();
}
public int id { get; set; }
public string text { get; set; }
public Dictionary<string, string> attributes { get; set; }
public List<EasyTreeNode> children { get; set; }
}
使用
/// <summary>
/// 获取功能权限
/// </summary>
/// <returns></returns>
[OutputCache(Duration=0,NoStore=true)]//去掉缓存
public ActionResult GetFuncs()
{
try
{
List<RoleFuncs> lsFucs = homeBll.GetRoleFuncsById(1);//获取角色的所有功能列表
List<EasyTreeNode> lsETN = GetChildNode(lsFucs, 0);
JavaScriptSerializer json = new JavaScriptSerializer();
string jsonstring = json.Serialize(lsETN);
return Content(jsonstring);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 递归
/// </summary>
/// <param name="lsFucs"></param>
/// <param name="funcid"></param>
/// <returns></returns>
public List<EasyTreeNode> GetChildNode(List<RoleFuncs> lsFucs, int funcid)
{
List<EasyTreeNode> lsNodes= new List<EasyTreeNode>();
foreach (var item in lsFucs)
{
if (item.ParentId == funcid)
{
EasyTreeNode etn = new EasyTreeNode();
etn.id = item.FunId;
etn.text = item.FunName;
etn.attributes.Add("Url",item.Url);
List<EasyTreeNode> lstemp= GetChildNode(lsFucs, item.Id);
etn.children = lstemp;
lsNodes.Add(etn);
}
}
return lsNodes;
}