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新手,希望各位大侠多多指教。
  • 相关阅读:
    appcan封装好的ajax,解决onDATA覆盖问题
    待研究
    mysql主从实验
    jQuery动态加载JS以减少服务器压力
    HTTP协议详解
    企业站收藏
    Linux查看程序端口占用情况
    大流量网站优化
    营销类网站
    Nginx (简体中文)
  • 原文地址:https://www.cnblogs.com/duanyuerui/p/6901648.html
Copyright © 2011-2022 走看看