首页 > 代码库 > Linq递归生成easyui-tree

Linq递归生成easyui-tree

我把整个类放这里大加参考:

public class ClassOrganization
    {
        static List<Model.ClassOrganization> org;

        public List<Model.ClassOrganization> GetOrgTree(string _pid)
        {
            List<Model.ClassOrganization> porg = new List<Model.ClassOrganization>();
            porg = org.Where(g => g.attributes == _pid).ToList();
            //List<Model.OrgTree> list_tree = new List<Model.OrgTree>();
            foreach (var sn in porg) {
                sn.children = org.Where(g => g.attributes == sn.id).ToList();
                GetOrgTree(sn.id);
            }
            return porg;
        }
        static ClassOrganization()
        {
            DAL.ClassOrganization dorg = new DAL.ClassOrganization();
            org = dorg.GetOrgTree();
        }
    }

这里的代码是我的BLL层里面的代码,至于辅助类,即Model里面的ClassOrgnization中的字段是按照easyui-tree需要的json格式,大家可以自己在博客园搜索源类。