自己写的 mvc 中 供 easy ui tree 用的类

42 篇文章 0 订阅
33 篇文章 0 订阅


    /// <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;
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值