easyui加载datagrid和treegrid的几种json数据格式

来源:互联网 发布:python升级到2.7 编辑:程序博客网 时间:2024/05/22 02:01

一、easyui加载datagrid的json数据格式

      (1)基础的数据格式

           

[html] view plain copy
  1. {"total":28,"rows":[  
  2.     {"productid":"FI-SW-01","productname":"Koi","unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"},  
  3.     {"productid":"K9-DL-01","productname":"Dalmation","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},  
  4.     {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":38.50,"attr1":"Venomless","itemid":"EST-11"},  
  5.     {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"},  
  6.     {"productid":"RP-LI-02","productname":"Iguana","unitcost":12.00,"status":"P","listprice":35.50,"attr1":"Green Adult","itemid":"EST-13"},  
  7.     {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":158.50,"attr1":"Tailless","itemid":"EST-14"},  
  8.     {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":83.50,"attr1":"With tail","itemid":"EST-15"},  
  9.     {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":23.50,"attr1":"Adult Female","itemid":"EST-16"},  
  10.     {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":89.50,"attr1":"Adult Male","itemid":"EST-17"},  
  11.     {"productid":"AV-CB-01","productname":"Amazon Parrot","unitcost":92.00,"status":"P","listprice":63.50,"attr1":"Adult Male","itemid":"EST-18"}  
  12. ]}  

      (2)带footer的数据格式

[html] view plain copy
  1. {"total":28,"rows":[  
  2.     {"productid":"FI-SW-01","unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"},  
  3.     {"productid":"K9-DL-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},  
  4.     {"productid":"RP-SN-01","unitcost":12.00,"status":"P","listprice":28.50,"attr1":"Venomless","itemid":"EST-11"},  
  5.     {"productid":"RP-SN-01","unitcost":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"},  
  6.     {"productid":"RP-LI-02","unitcost":12.00,"status":"P","listprice":35.50,"attr1":"Green Adult","itemid":"EST-13"},  
  7.     {"productid":"FL-DSH-01","unitcost":12.00,"status":"P","listprice":158.50,"attr1":"Tailless","itemid":"EST-14"},  
  8.     {"productid":"FL-DSH-01","unitcost":12.00,"status":"P","listprice":83.50,"attr1":"With tail","itemid":"EST-15"},  
  9.     {"productid":"FL-DLH-02","unitcost":12.00,"status":"P","listprice":63.50,"attr1":"Adult Female","itemid":"EST-16"},  
  10.     {"productid":"FL-DLH-02","unitcost":12.00,"status":"P","listprice":89.50,"attr1":"Adult Male","itemid":"EST-17"},  
  11.     {"productid":"AV-CB-01","unitcost":92.00,"status":"P","listprice":63.50,"attr1":"Adult Male","itemid":"EST-18"}  
  12. ],"footer":[  
  13.     {"unitcost":19.80,"listprice":60.40,"productid":"Average:"},  
  14.     {"unitcost":198.00,"listprice":604.00,"productid":"Total:"}  
  15. ]}  


二、easyui加载treegrid的json数据格式

        (1)基本的数据结构

[html] view plain copy
  1. [{  
  2.     "id":1,  
  3.     "name":"C",  
  4.     "size":"",  
  5.     "date":"02/19/2010",  
  6.     "children":[{  
  7.         "id":2,  
  8.         "name":"Program Files",  
  9.         "size":"120 MB",  
  10.         "date":"03/20/2010",  
  11.         "children":[{  
  12.             "id":21,  
  13.             "name":"Java",  
  14.             "size":"",  
  15.             "date":"01/13/2010",  
  16.             "state":"closed",  
  17.             "children":[{  
  18.                 "id":211,  
  19.                 "name":"java.exe",  
  20.                 "size":"142 KB",  
  21.                 "date":"01/13/2010"  
  22.             },{  
  23.                 "id":212,  
  24.                 "name":"jawt.dll",  
  25.                 "size":"5 KB",  
  26.                 "date":"01/13/2010"  
  27.             }]  
  28.         },{  
  29.             "id":22,  
  30.             "name":"MySQL",  
  31.             "size":"",  
  32.             "date":"01/13/2010",  
  33.             "state":"closed",  
  34.             "children":[{  
  35.                 "id":221,  
  36.                 "name":"my.ini",  
  37.                 "size":"10 KB",  
  38.                 "date":"02/26/2009"  
  39.             },{  
  40.                 "id":222,  
  41.                 "name":"my-huge.ini",  
  42.                 "size":"5 KB",  
  43.                 "date":"02/26/2009"  
  44.             },{  
  45.                 "id":223,  
  46.                 "name":"my-large.ini",  
  47.                 "size":"5 KB",  
  48.                 "date":"02/26/2009"  
  49.             }]  
  50.         }]  
  51.     },{  
  52.         "id":3,  
  53.         "name":"eclipse",  
  54.         "size":"",  
  55.         "date":"01/20/2010",  
  56.         "children":[{  
  57.             "id":31,  
  58.             "name":"eclipse.exe",  
  59.             "size":"56 KB",  
  60.             "date":"05/19/2009"  
  61.         },{  
  62.             "id":32,  
  63.             "name":"eclipse.ini",  
  64.             "size":"1 KB",  
  65.             "date":"04/20/2010"  
  66.         },{  
  67.             "id":33,  
  68.             "name":"notice.html",  
  69.             "size":"7 KB",  
  70.             "date":"03/17/2005"  
  71.         }]  
  72.     }]  
  73. }]  

   (2)_parentId的数据格式,字段_parentId必不可少,且名称唯一

[html] view plain copy
  1. {"total":7,"rows":[  
  2.     {"id":1,"name":"All Tasks","begin":"3/4/2010","end":"3/20/2010","progress":60,"iconCls":"icon-ok"},  
  3.     {"id":2,"name":"Designing","begin":"3/4/2010","end":"3/10/2010","progress":100,"_parentId":1,"state":"closed"},  
  4.     {"id":21,"name":"Database","persons":2,"begin":"3/4/2010","end":"3/6/2010","progress":100,"_parentId":2},  
  5.     {"id":22,"name":"UML","persons":1,"begin":"3/7/2010","end":"3/8/2010","progress":100,"_parentId":2},  
  6.     {"id":23,"name":"Export Document","persons":1,"begin":"3/9/2010","end":"3/10/2010","progress":100,"_parentId":2},  
  7.     {"id":3,"name":"Coding","persons":2,"begin":"3/11/2010","end":"3/18/2010","progress":80},  
  8.     {"id":4,"name":"Testing","persons":1,"begin":"3/19/2010","end":"3/20/2010","progress":20}  
  9. ],"footer":[  
  10.     {"name":"Total Persons:","persons":7,"iconCls":"icon-sum"}  
  11. ]}  
     (3)带footer的_parentId数据格式

[html] view plain copy
  1. {"total":9,"rows":[  
  2.     {"id":1,"region":"Wyoming"},  
  3.     {"id":11,"region":"Albin","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":1},  
  4.     {"id":12,"region":"Canon","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":1},  
  5.     {"id":13,"region":"Egbert","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":1},  
  6.     {"id":2,"region":"Washington"},  
  7.     {"id":21,"region":"Bellingham","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":2},  
  8.     {"id":22,"region":"Chehalis","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":2},  
  9.     {"id":23,"region":"Ellensburg","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":2},  
  10.     {"id":24,"region":"Monroe","f1":2000,"f2":1800,"f3":1903,"f4":2183,"f5":2133,"f6":1923,"f7":2018,"f8":1838,"_parentId":2}  
  11. ],"footer":[  
  12.     {"region":"Total","f1":14000,"f2":12600,"f3":13321,"f4":15281,"f5":14931,"f6":13461,"f7":14126,"f8":12866}  
  13. ]}  

三、总结

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

原创粉丝点击