0

我有一个包含如下文件夹的信息数组:

[
               {
                  "ACLID" : 0,
                  "ID" : 100,
                  "auditInfoVersion" : 3435973836,
                  "createBy" : 2,
                  "createDate" : "04/12/2012 17:38:46",
                  "isSubFolder" : 0,
                  "name" : "Piyush1",
                  "objectType" : 3,
               -->"parentID" : 3,
                  "policyID" : 2,
                  "sDescription" : "",
                  "updateBy" : 2,
                  "updateDate" : "04/12/2012 17:38:46"
               },
               {
                  "ACLID" : 0,
                  "ID" : 102,
                  "auditInfoVersion" : 3435973836,
                  "createBy" : 2,
                  "createDate" : "05/10/2012 12:38:25",
                  "isSubFolder" : 0,
                  "name" : "New",
                  "objectType" : 3,
               -->"parentID" : 3,
                  "policyID" : 2,
                  "sDescription" : "",
                  "updateBy" : 2,
                  "updateDate" : "05/10/2012 12:38:25"
               },
               {
                  "ACLID" : 0,
                  "ID" : 103,
                  "auditInfoVersion" : 3435973836,
                  "createBy" : 2,
                  "createDate" : "05/14/2012 18:00:22",
                  "isSubFolder" : 0,
                  "name" : "SegFolderWithDiffPolicy",
                  "objectType" : 3,
               -->"parentID" : 3,
                  "policyID" : 39,
                  "sDescription" : "",
                  "updateBy" : 2,
                  "updateDate" : "05/14/2012 18:00:22"
               },
               {
                  "ACLID" : 0,
                  "ID" : 104,
                  "auditInfoVersion" : 3435973836,
                  "createBy" : 2,
                  "createDate" : "05/17/2012 14:13:56",
                  "isSubFolder" : 0,
                  "name" : "New1",
                  "objectType" : 3,
               -->"parentID" : 100,
                  "policyID" : 2,
                  "sDescription" : "",
                  "updateBy" : 2,
                  "updateDate" : "05/17/2012 14:13:56"
               },
               {
                  "ACLID" : 0,
                  "ID" : 105,
                  "auditInfoVersion" : 3435973836,
                  "createBy" : 2,
                  "createDate" : "05/17/2012 14:14:13",
                  "isSubFolder" : 0,
                  "name" : "abcasdna",
                  "objectType" : 3,
               -->"parentID" : 104,
                  "policyID" : 2,
                  "sDescription" : "",
                  "updateBy" : 2,
                  "updateDate" : "05/17/2012 14:14:13"
               },
               {
                  "ACLID" : 0,
                  "ID" : 106,
                  "auditInfoVersion" : 3435973836,
                  "createBy" : 2,
                  "createDate" : "05/18/2012 12:51:39",
                  "isSubFolder" : 0,
                  "name" : "new2",
                  "objectType" : 3,
               -->"parentID" : 100,
                  "policyID" : 2,
                  "sDescription" : "",
                  "updateBy" : 2,
                  "updateDate" : "05/18/2012 12:51:39"
               }
            ]

现在所需的数据类型是:

[{
    name:'Piyush1',
    children: [{
        name: 'New1',
        children:[{
            name: 'abcasdna'
        }]
    },{
        name: 'New2'
    }]
},{
    name: 'New'
}]

现在的问题是,可以有任意数量的文件夹和任意级别的层次结构。

那么有没有办法可以实现这种转换?

4

0 回答 0