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;

        }

posted @ 2017-05-24 23:53  段十八丶  阅读(1170)  评论(0编辑  收藏  举报