zoukankan      html  css  js  c++  java
  • Tree数据格式 Easyui

    public ActionResult GetTreeJson()

            {

                List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();

                var list = bpDAL.GetList(o => o.Tree.ParentId == 0).ToList();

                int count = list.Count();

                for (int i = 0; i < count; i++)

                {

                    Dictionary<string, object> row = new Dictionary<string, object>();

                    row.Add("id", list[i].Id);

                    row.Add("text", list[i].PowerName);

                    row.Add("state", list[i].Tree.IsLeaf == false ? "closed" : "open");

                    row.Add("children", GetTreeChildrenJson(list[i].Id));

                    rows.Add(row);

                }

                return Json(rows, "text/html", JsonRequestBehavior.AllowGet);

     

            }

     

            public List<Dictionary<string, object>> GetTreeChildrenJson(int Id)

            {

                List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();

                var list = bpDAL.GetList(o => o.Tree.ParentId == Id).ToList();

                int count = list.Count();

                for (int i = 0; i < count; i++)

                {

                    Dictionary<string, object> row = new Dictionary<string, object>();

                    if (list[i].Tree.IsLeaf == false)

                    {

                        row.Add("id", list[i].Id);

                        row.Add("text", list[i].PowerName);

                        row.Add("state", list[i].Tree.IsLeaf == false ? "closed" : "open");

                        row.Add("children", GetTreeChildrenJson(list[i].Id));

                        rows.Add(row);

                    }

                    else

                    {

                        row.Add("id", list[i].Id);

                        row.Add("text", list[i].PowerName);

                        row.Add("state", list[i].Tree.IsLeaf == false ? "closed" : "open");

                        rows.Add(row);

                    }

                }

                return rows;

            }

    NET新手,希望各位大侠多多指教。
  • 相关阅读:
    计算中文混合字符串长度(一)
    PHP截取含中文的混合字符串长度的函数
    获取星座的JS函数
    获取生日对应星座的PHP函数
    简单的 jQuery 浮动层随窗口滚动滑动插件实例
    MD5算法实现
    70. Climbing Stairs QuestionEditorial Solution
    167. Two Sum II
    167. Two Sum II
    303. Range Sum Query
  • 原文地址:https://www.cnblogs.com/duanyuerui/p/6901648.html
Copyright © 2011-2022 走看看