码迷,mamicode.com
首页 > 其他好文 > 详细

Easyui TreeGrid数据源

时间:2020-05-21 14:33:33      阅读:49      评论:0      收藏:0      [点我收藏+]

标签:ade   节点   tin   derby   pen   测试   return   ini   eclipse   

一:基础Json数据格式(多层次)--(用children表示子节点的集合

技术图片
[{
    "id":1,
    "name":"C",
    "size":"",
    "date":"02/19/2010",
    "children":[{
        "id":2,
        "name":"Program Files",
        "size":"120 MB",
        "date":"03/20/2010",
        "children":[{
            "id":21,
            "name":"Java",
            "size":"",
            "date":"01/13/2010",
            "state":"closed",
            "children":[{
                "id":211,
                "name":"java.exe",
                "size":"142 KB",
                "date":"01/13/2010"
            },{
                "id":212,
                "name":"jawt.dll",
                "size":"5 KB",
                "date":"01/13/2010"
            }]
        },{
            "id":22,
            "name":"MySQL",
            "size":"",
            "date":"01/13/2010",
            "state":"closed",
            "children":[{
                "id":221,
                "name":"my.ini",
                "size":"10 KB",
                "date":"02/26/2009"
            },{
                "id":222,
                "name":"my-huge.ini",
                "size":"5 KB",
                "date":"02/26/2009"
            },{
                "id":223,
                "name":"my-large.ini",
                "size":"5 KB",
                "date":"02/26/2009"
            }]
        }]
    },{
        "id":3,
        "name":"eclipse",
        "size":"",
        "date":"01/20/2010",
        "children":[{
            "id":31,
            "name":"eclipse.exe",
            "size":"56 KB",
            "date":"05/19/2009"
        },{
            "id":32,
            "name":"eclipse.ini",
            "size":"1 KB",
            "date":"04/20/2010"
        },{
            "id":33,
            "name":"notice.html",
            "size":"7 KB",
            "date":"03/17/2005"
        }]
    }]
}]
技术图片

二:_parentId的数据格式 --(用_parentId表示指向上级节点id

技术图片
{"total":7,"rows":[
    {"id":1,"name":"All Tasks","begin":"3/4/2010","end":"3/20/2010","progress":60,"iconCls":"icon-ok"},
    {"id":2,"name":"Designing","begin":"3/4/2010","end":"3/10/2010","progress":100,"_parentId":1,"state":"closed"},
    {"id":21,"name":"Database","persons":2,"begin":"3/4/2010","end":"3/6/2010","progress":100,"_parentId":2},
    {"id":22,"name":"UML","persons":1,"begin":"3/7/2010","end":"3/8/2010","progress":100,"_parentId":2},
    {"id":23,"name":"Export Document","persons":1,"begin":"3/9/2010","end":"3/10/2010","progress":100,"_parentId":2},
    {"id":3,"name":"Coding","persons":2,"begin":"3/11/2010","end":"3/18/2010","progress":80},
    {"id":4,"name":"Testing","persons":1,"begin":"3/19/2010","end":"3/20/2010","progress":20}
],"footer":[
    {"name":"Total Persons:","persons":7,"iconCls":"icon-sum"}
]}
技术图片

我的代码注意红色段:

技术图片
public ActionResult GetSpaceList(int SpaceId)
        {
            var result = spaceBll.LoadEntities(u => u.ParentId == SpaceId).OrderBy(u=>u.ParentId).ToList();
            
            var  list = result.Select(b => new
            {
                id = b.SpaceId ==0?"0":b.SpaceId.ToString(),
                text = b.SpaceName,
                _parentId = b.ParentId == 0 ?"0":b.ParentId.ToString(),
                CityCode = b.CityCode,
                b.FirstChar,
                mm_SpaceTypeMas = b.mm_SpaceTypeMas,
                state = ((b.SpaceTypeId == 5 || b.SpaceTypeId == 6) ? "open" : "closed")
            }).ToList();

            List<object> test = new List<object>();
            test.Add(new {
                id ="0",
                text = "所有位置",
                state = "open"
            });

            test.AddRange(list);
             return Json(new { total = result.Count(), rows = test });
技术图片

 

三:带footer的_parentId数据格式(footer怎么用还没测试过

技术图片
{"total":9,"rows":[
    {"id":1,"region":"Wyoming"},
    {"id":11,"region":"Albin","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":1},
    {"id":12,"region":"Canon","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":1},
    {"id":13,"region":"Egbert","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":1},
    {"id":2,"region":"Washington"},
    {"id":21,"region":"Bellingham","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":2},
    {"id":22,"region":"Chehalis","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":2},
    {"id":23,"region":"Ellensburg","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":2},
    {"id":24,"region":"Monroe","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":2}
],"footer":[
    {"region":"Total","f1":14000,"f2":12600,"f3":13321,"f4":15281,"f5":14931,"f6":13461,"f7":14126,"f8":12866}
]}
技术图片

 

在easyui加载数据时,必须遵循上述的几种数据规则,否则数据不能正确显示,字段名称可以根据自己的情况定义,但是格式必须保持一致,在treegrid的加载时,遇到级联的情况需要主要_parentId字段名称。

Easyui TreeGrid数据源

标签:ade   节点   tin   derby   pen   测试   return   ini   eclipse   

原文地址:https://www.cnblogs.com/linybo/p/12930543.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!