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新手,希望各位大侠多多指教。
  • 相关阅读:
    新建存储过程
    c#List移除列表中的元素
    学习总结初篇:发现问题
    webpack的几个使用方法
    Does Lamda expression return value?
    委托的最佳科普解释
    正则表达式字符匹配攻略
    Beta冲刺 第一天
    ###Beta准备
    高校征信系统项目Postmortem结果
  • 原文地址:https://www.cnblogs.com/duanyuerui/p/6901648.html
Copyright © 2011-2022 走看看