打赏

linq在获取部门层级树种的应用

public string GetNavigationsJson()
        {
            AjaxA_NAVIGATIONS ajaxnavigations = new AjaxA_NAVIGATIONS();
            IList<A_NAVIGATIONS> listnavigations = ajaxnavigations.GetNavigations();

            return JSONHelper.ToJson(GetNavigations(listnavigations,0));
        }

        public IEnumerable<object> GetNavigations(IList<A_NAVIGATIONS> navigations, int parentId)
        {
        var menus =
                    navigations.Where(n => n.PARENTID == parentId && n.ISVISIBLE == 1)
                               .OrderBy(n => n.SORTNUM)
                               .Select(n => new
                               {
                                   id = n.KEYID,
                                   text = n.NAVTITLE,
                                   n.ICONCLS,
                                   attributes = new
                                   {
                                       url = n.LINKURL,
                                       n.ICONURL,
                                       parentid = n.PARENTID,
                                       sortnum = n.SORTNUM,
                                       n.BIGIMAGEURL,
                                       n.ISNEWWINDOW,
                                       n.WINWIDTH,
                                       n.WINHEIGHT
                                   },
                                   state = parentId == 0
                                   ? "open"
                                   :  "closed",
                                   children = GetNavigations(navigations, n.KEYID)
                               });
            return menus;
        }
    }

 

posted @ 2017-04-14 14:37  刘奇云  阅读(349)  评论(0编辑  收藏  举报