zoukankan      html  css  js  c++  java
  • c# 格式化easyui tree

    id text False pid
    2 �û� True 0
    3 ���� True 1
    4 ����Ա False 2
    5 ����Ա2 False 3
    NULL NULL NULL NULL

     public ActionResult GetIndex()
            {
                CRMEntities db = new CRMEntities();
                EasyUIJsonTree root = new EasyUIJsonTree()
                {
                    text = "菜单根节点"
                };
                IList<Trees> list = db.Trees.ToList();
                if (list != null && list.Count > 0)
                {
                   b.GetTree(root, list);
                }           
                List<object> l = new List<object>();
                l.Add(root);
                return Json(l, JsonRequestBehavior.AllowGet);
                //return JsonResult(new { root });
                // Response.Write(JsonConvert.SerializeObject(new EasyUIJsonTree[] { root }));
            }

    public class b
        {

       public static void GetTree(EasyUIJsonTree parent, IList<Trees> list, int? parentID = 0)
            {
                var query = list.Where(m => m.pid == parentID);
                if (query.Any())
                {
                    if (parent.children == null)
                    {
                        parent.children = new List<EasyUIJsonTree>();
                    }
                    foreach (Trees mv in query)
                    {
                        EasyUIJsonTree child = new EasyUIJsonTree()
                        {
                            id = mv.id.ToString(),
                            text = mv.text,
                            //attributes = new { Url = mv.Url }
                        };
                        parent.children.Add(child);
                        b.GetTree(child, list, mv.id);
                    }
                }
            }
        }
        public class EasyUIJsonTree
        {
            public string id { get; set; }
            public string text { get; set; }
            //public string iconCls { get; set; }
            public IList<EasyUIJsonTree> children { get; set; }
            public object attributes { get; set; }
        }

  • 相关阅读:
    bzoj 2763: [JLOI2011]飞行路线
    2008年NOI全国竞赛 假面舞会
    八数码(双向宽搜)
    poj 1988 Cube Stacking && codevs 1540 银河英雄传说(加权并茶几)
    codevs 3693 数三角形
    bzoj 3831 Little Bird (单调队列优化dp)
    hdu 3530 Subsequence
    poj 2823 Sliding Window(单调队列)
    线段树各种小练习
    codevs 2449 骑士精神 (IDDfs)
  • 原文地址:https://www.cnblogs.com/ruiyuan/p/11535733.html
Copyright © 2011-2022 走看看