easyui treegrid 关于请求的json格式的封装处理

来源:互联网 发布:js正则表达式实例 编辑:程序博客网 时间:2024/06/05 02:08

由于treegrid有层级结构,因此传送的json格式也要体现父子之间的层级关系,treegrid才能显示正确,在官网中我找到了2中treegrid识别的json格式,第一种:

{"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"}]}
(关于如何找到此处json格式,可参看作者:爱你的小伟3的文章)
这种格式中:total为数据总数,rows为要显示的数据。
第二种:
[{"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"}]}]}]
(json数据可在jquery官网中的basic treegrid中找到,找到的方法同上)

我在项目中的使用了第二种方法,其实两种方法都可以,就看自己的习惯以及具体的数据。先贴出我的原始的json数据,由于我关联的表较多,因此我将要先是的数据分2次查询,然后都分装到同一对象当中,下面这部分是线体,工位的信息,他们之间的层级关系是id与parentid的关系来确定。

[    {        "actualTaktTime": 0,        "biwBomId": 0,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "ORG",        "bopTrProjectLayoutId": 0,        "bopTrProjectLayoutLayoutId": 0,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "",        "functionType": "2",        "id": 2000063,        "instanceNameZh": "",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "线体01",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 1,        "parentID": 2000060,        "partNumber": "",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "",        "strSequence": "",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 2000050,        "variateCondition": ""    },    {        "actualTaktTime": 0,        "biwBomId": 0,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "ORG",        "bopTrProjectLayoutId": 0,        "bopTrProjectLayoutLayoutId": 0,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "",        "functionType": "2",        "id": 2000064,        "instanceNameZh": "",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "线体02",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 2,        "parentID": 2000060,        "partNumber": "",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "",        "strSequence": "",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 2000053,        "variateCondition": ""    },    {        "actualTaktTime": 0,        "biwBomId": 0,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "ORG",        "bopTrProjectLayoutId": 0,        "bopTrProjectLayoutLayoutId": 0,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "",        "functionType": "2",        "id": 2000065,        "instanceNameZh": "",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "线体03",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 1,        "parentID": 2000061,        "partNumber": "",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "",        "strSequence": "",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 2000057,        "variateCondition": ""    },    {        "actualTaktTime": 0,        "biwBomId": 0,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "ORG",        "bopTrProjectLayoutId": 0,        "bopTrProjectLayoutLayoutId": 0,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "",        "functionType": "2",        "id": 2000066,        "instanceNameZh": "",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "线体04",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 2,        "parentID": 2000061,        "partNumber": "",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "",        "strSequence": "",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 2000058,        "variateCondition": ""    },    {        "actualTaktTime": 0,        "biwBomId": 0,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "ORG",        "bopTrProjectLayoutId": 0,        "bopTrProjectLayoutLayoutId": 0,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "",        "functionType": "1",        "id": 2000067,        "instanceNameZh": "",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "工位01",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 1,        "parentID": 2000063,        "partNumber": "",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "",        "strSequence": "",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 2000051,        "variateCondition": ""    },    {        "actualTaktTime": 0,        "biwBomId": 0,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "ORG",        "bopTrProjectLayoutId": 0,        "bopTrProjectLayoutLayoutId": 0,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "",        "functionType": "1",        "id": 2000068,        "instanceNameZh": "",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "工位02",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 2,        "parentID": 2000063,        "partNumber": "",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "",        "strSequence": "",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 2000052,        "variateCondition": ""    },    {        "actualTaktTime": 0,        "biwBomId": 0,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "ORG",        "bopTrProjectLayoutId": 0,        "bopTrProjectLayoutLayoutId": 0,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "",        "functionType": "1",        "id": 2000069,        "instanceNameZh": "",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "工位03",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 1,        "parentID": 2000064,        "partNumber": "",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "",        "strSequence": "",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 2000054,        "variateCondition": ""    },    {        "actualTaktTime": 0,        "biwBomId": 0,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "ORG",        "bopTrProjectLayoutId": 0,        "bopTrProjectLayoutLayoutId": 0,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "",        "functionType": "1",        "id": 2000070,        "instanceNameZh": "",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "工位04",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 2,        "parentID": 2000064,        "partNumber": "",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "",        "strSequence": "",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 2000055,        "variateCondition": ""    }]
第二部分数据在这:这部分的数据时零件信息,是在工位下面,他与工位之间的关系是bopTrProjectLayoutLayoutId与上面的id相同,现在要把这两部分的数据分装成第二种格式的数据。

[    {        "actualTaktTime": 0,        "biwBomId": 67297,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "",        "bopTrProjectLayoutId": 2000051,        "bopTrProjectLayoutLayoutId": 2000067,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "A05F",        "functionType": "",        "id": 0,        "instanceNameZh": "前保横梁总成",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 0,        "parentID": 0,        "partNumber": "C00048649",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "511",        "strSequence": "001002001001",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 0,        "variateCondition": "C00048876:Q10 = \"Q10A\""    },    {        "actualTaktTime": 0,        "biwBomId": 67339,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "",        "bopTrProjectLayoutId": 2000052,        "bopTrProjectLayoutLayoutId": 2000068,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "A19M",        "functionType": "",        "id": 0,        "instanceNameZh": "仪表板横梁连接板",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 0,        "parentID": 0,        "partNumber": "C00055743",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "511",        "strSequence": "001002001004",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 0,        "variateCondition": ""    },    {        "actualTaktTime": 0,        "biwBomId": 67341,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "",        "bopTrProjectLayoutId": 2000052,        "bopTrProjectLayoutLayoutId": 2000068,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "A05E",        "functionType": "",        "id": 0,        "instanceNameZh": "前侧板总成",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 0,        "parentID": 0,        "partNumber": "C00056366",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "511",        "strSequence": "001002001006",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 0,        "variateCondition": "C00048876:Q10 = \"Q10X\""    },    {        "actualTaktTime": 0,        "biwBomId": 67353,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "",        "bopTrProjectLayoutId": 2000051,        "bopTrProjectLayoutLayoutId": 2000067,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "A05E",        "functionType": "",        "id": 0,        "instanceNameZh": "前侧板总成",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 0,        "parentID": 0,        "partNumber": "C00056367",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "511",        "strSequence": "001002001007",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 0,        "variateCondition": "C00048876:Q10 = \"Q10X\""    },    {        "actualTaktTime": 0,        "biwBomId": 67380,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "",        "bopTrProjectLayoutId": 2000052,        "bopTrProjectLayoutLayoutId": 2000068,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "A05E",        "functionType": "",        "id": 0,        "instanceNameZh": "前侧板总成",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 0,        "parentID": 0,        "partNumber": "C00065233",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "511",        "strSequence": "001002001009",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 0,        "variateCondition": "C00048876:Q10 = \"Q10A\""    },    {        "actualTaktTime": 0,        "biwBomId": 67397,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "",        "bopTrProjectLayoutId": 2000054,        "bopTrProjectLayoutLayoutId": 2000069,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "A20R",        "functionType": "",        "id": 0,        "instanceNameZh": "安装支架",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 0,        "parentID": 0,        "partNumber": "C00049508",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "511",        "strSequence": "001002001010",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 0,        "variateCondition": ""    },    {        "actualTaktTime": 0,        "biwBomId": 67398,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "",        "bopTrProjectLayoutId": 2000055,        "bopTrProjectLayoutLayoutId": 2000070,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "A16M",        "functionType": "",        "id": 0,        "instanceNameZh": "风窗流水槽总成",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 0,        "parentID": 0,        "partNumber": "C00048461",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "511",        "strSequence": "001002001011",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 0,        "variateCondition": "C00048876:B20 = \"B201\" or C00048876:B20 = \"B203\""    },    {        "actualTaktTime": 0,        "biwBomId": 72206,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "",        "bopTrProjectLayoutId": 2000051,        "bopTrProjectLayoutLayoutId": 2000067,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "A01B",        "functionType": "",        "id": 0,        "instanceNameZh": "后轮罩衬板安装支架",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 0,        "parentID": 0,        "partNumber": "C00049843",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "5A2",        "strSequence": "001022001002012",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 0,        "variateCondition": ""    },    {        "actualTaktTime": 0,        "biwBomId": 72207,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "",        "bopTrProjectLayoutId": 2000051,        "bopTrProjectLayoutLayoutId": 2000067,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "A01B",        "functionType": "",        "id": 0,        "instanceNameZh": "侧栏板内板总成",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 0,        "parentID": 0,        "partNumber": "C00052962",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "5A2",        "strSequence": "001022001003",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 0,        "variateCondition": "'FB-SK81':'470' = \"470A\" and 'FB-SK81':'410' = \"410S\""    },    {        "actualTaktTime": 0,        "biwBomId": 72209,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "",        "bopTrProjectLayoutId": 2000051,        "bopTrProjectLayoutLayoutId": 2000067,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "A01B",        "functionType": "",        "id": 0,        "instanceNameZh": "侧栏外板支撑加强板",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 0,        "parentID": 0,        "partNumber": "C00049790",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "5A2",        "strSequence": "001022001003001001",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 0,        "variateCondition": ""    },    {        "actualTaktTime": 0,        "biwBomId": 72507,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "",        "bopTrProjectLayoutId": 2000051,        "bopTrProjectLayoutLayoutId": 2000067,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "A01D",        "functionType": "",        "id": 0,        "instanceNameZh": "堵盖",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 0,        "parentID": 0,        "partNumber": "C00043329",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "5A4",        "strSequence": "001023001006",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 0,        "variateCondition": "'FB-SK81':'470' = \"470A\" and 'FB-SK81':'410' = \"410D\""    },    {        "actualTaktTime": 0,        "biwBomId": 72508,        "bopTmLayoutChildren": [],        "bopTmLayoutDefinLayoutType": "",        "bopTrProjectLayoutId": 2000051,        "bopTrProjectLayoutLayoutId": 2000067,        "bopTrProjectLayoutList": [],        "children": [],        "childrenMap": {},        "code": "",        "createBy": 0,        "createDate": null,        "createDateStr": "",        "description": "",        "ffc": "A01D",        "functionType": "",        "id": 0,        "instanceNameZh": "堵盖",        "lastUpdateBy": 0,        "lastUpdateDate": null,        "lastUpdateDateStr": "",        "layoutName": "",        "layoutStatus": 0,        "layoutType": "",        "name": "",        "nameId": 0,        "nodeType": 0,        "orderNo": 0,        "parentID": 0,        "partNumber": "C00043329",        "plantID": 0,        "processList": [],        "rowVersion": 0,        "shortSvpps": "5A4",        "strSequence": "001023001007",        "superStatus": 1,        "taktTime": 0,        "target": 0,        "trProjectLayoutId": 0,        "variateCondition": "'FB-SK81':'470' = \"470A\" and 'FB-SK81':'410' = \"410D\""    }]
我的做法是在action中通过判断先将所有的工位工段放到一个map当中,当然BopTmLayout对象中要有child属性,然后将工位放进对应的线体当中,然后再将零件信息放入工位当中。

public String uploadOper(){//获取该项目下所有的工位和工段List<BopTmLayout> listUploadPart = bopTmLayoutService.findUploadPart(bopTmDataSet.getId());List<BopTmLayout> layouts=new ArrayList<BopTmLayout>();//Map<Integer,BopTmLayout> layoutMap=new HashMap<Integer,BopTmLayout>();//存放线体和工位for(BopTmLayout layout:listUploadPart){BopTmLayout mapLayout = layoutMap.get(layout.getParentID());if(null!=mapLayout){mapLayout.getChildren().add(layout);}else{layouts.add(layout);}layoutMap.put(layout.getId(), layout);}//目前已经上件的零件信息 List<BopTmLayout> listUploadOper = bopTmLayoutService.uploadOper(bopTmDataSet.getId());//目前已经上件的零件信息 for(BopTmLayout layoutBiwBom:listUploadOper){ layoutBiwBom.setId(layoutBiwBom.getBopTrProjectLayoutId()+layoutBiwBom.getBiwBomId());// layoutMap.get(layoutBiwBom.getBopTrProjectLayoutLayoutId()).getChildren().add(layoutBiwBom); }  JSONArray.fromObject(layouts).toString();return ajaxText(JSONArray.fromObject(layouts).toString());}
效果如下:





0 0