SOURCE

let resources = JSON.parse('[
      {
          "id": "042997e3469b11e89b3d00163e2eeb30", 
          "createTime": "2018-04-23 02:07:04", 
          "lastUpdateTime": "2018-04-26 04:15:09", 
          "tenantId": "10086", 
          "parentId": "815b0f70446e11e8b1a600163e2eeb30", 
          "templateId": "2", 
          "name": "update", 
          "code": "test.test001", 
          "serverIp": "", 
          "serverPort": null, 
          "icon": "", 
          "sort": null, 
          "remark": "", 
          "status": "run"
      }, 
      {
          "id": "04decf10485911e88a4200163e2eeb30", 
          "createTime": "2018-04-25 07:19:41", 
          "lastUpdateTime": "2018-04-25 10:35:59", 
          "tenantId": "10086", 
          "parentId": "2", 
          "templateId": "", 
          "name": "22", 
          "code": null, 
          "serverIp": "", 
          "serverPort": null, 
          "icon": "", 
          "sort": null, 
          "remark": "", 
          "status": "run"
      }, 
      {
          "id": "344f4011485c11e88a4200163e2eeb30", 
          "createTime": "2018-04-25 07:42:29", 
          "lastUpdateTime": "2018-04-25 07:42:29", 
          "tenantId": "10086", 
          "parentId": "0(根节点)", 
          "templateId": "", 
          "name": "cc", 
          "code": null, 
          "serverIp": "", 
          "serverPort": null, 
          "icon": "", 
          "sort": "0", 
          "remark": "", 
          "status": "run"
      }, 
      {
          "id": "572c9b20487311e895fd00163e2eeb30", 
          "createTime": "2018-04-25 10:28:06", 
          "lastUpdateTime": "2018-04-26 03:30:28", 
          "tenantId": "10086", 
          "parentId": "2", 
          "templateId": "", 
          "name": "mmmm", 
          "code": null, 
          "serverIp": "", 
          "serverPort": null, 
          "icon": "", 
          "sort": null, 
          "remark": "", 
          "status": "run"
      }, 
      {
          "id": "6572b28b482711e88a4200163e2eeb30", 
          "createTime": "2018-04-25 01:24:28", 
          "lastUpdateTime": "2018-04-25 09:19:26", 
          "tenantId": "10086", 
          "parentId": "10086", 
          "templateId": "2", 
          "name": "2", 
          "code": null, 
          "serverIp": "", 
          "serverPort": null, 
          "icon": "", 
          "sort": null, 
          "remark": "", 
          "status": "run"
      }, 
      {
          "id": "815b0f70446e11e8b1a600163e2eeb30", 
          "createTime": "2018-04-20 07:43:24", 
          "lastUpdateTime": "2018-04-20 07:45:37", 
          "tenantId": "10086", 
          "parentId": "0", 
          "templateId": "123", 
          "name": "资源修改测试", 
          "code": "test.test01", 
          "serverIp": "127.0.0.1", 
          "serverPort": "8080", 
          "icon": "http://localhost:8080/images/123.jpg", 
          "sort": "1", 
          "remark": "测试子服务1详细说明", 
          "status": "enable"
      }, 
      {
          "id": "8b5e2dc6490111e88ad700163e2eeb30", 
          "createTime": "2018-04-26 03:26:02", 
          "lastUpdateTime": "2018-04-26 03:26:02", 
          "tenantId": "10086", 
          "parentId": "0", 
          "templateId": "2", 
          "name": "mm", 
          "code": null, 
          "serverIp": "", 
          "serverPort": null, 
          "icon": "", 
          "sort": "0", 
          "remark": "", 
          "status": "run"
      }, 
      {
          "id": "8d17ab21446e11e8b1a600163e2eeb30", 
          "createTime": "2018-04-20 07:43:44", 
          "lastUpdateTime": "2018-04-20 07:43:44", 
          "tenantId": "10086", 
          "parentId": "815b0f70446e11e8b1a600163e2eeb30", 
          "templateId": "123", 
          "name": "修改-测试子服务1", 
          "code": "text.text002", 
          "serverIp": "127.0.0.1", 
          "serverPort": "8080", 
          "icon": "http://localhost:8080/images/123.jpg", 
          "sort": "1", 
          "remark": "测试子服务1详细说明", 
          "status": "enable"
      }, 
      {
          "id": "aada6b1148ed11e895fd00163e2eeb30", 
          "createTime": "2018-04-26 01:03:45", 
          "lastUpdateTime": "2018-04-26 01:03:45", 
          "tenantId": "10086", 
          "parentId": "1", 
          "templateId": "", 
          "name": "测试add", 
          "code": null, 
          "serverIp": "", 
          "serverPort": null, 
          "icon": "", 
          "sort": "0", 
          "remark": "", 
          "status": "run"
      }, 
      {
          "id": "b2341587490211e88ad700163e2eeb30", 
          "createTime": "2018-04-26 03:34:16", 
          "lastUpdateTime": "2018-04-26 04:03:48", 
          "tenantId": "10086", 
          "parentId": "815b0f70446e11e8b1a600163e2eeb30", 
          "templateId": "0", 
          "name": "update", 
          "code": null, 
          "serverIp": "", 
          "serverPort": null, 
          "icon": "", 
          "sort": null, 
          "remark": "", 
          "status": "run"
      }, 
      {
          "id": "b472b8b548f311e88ad700163e2eeb30", 
          "createTime": "2018-04-26 01:46:58", 
          "lastUpdateTime": "2018-04-26 01:46:58", 
          "tenantId": "10086", 
          "parentId": "2", 
          "templateId": "", 
          "name": "2", 
          "code": null, 
          "serverIp": "", 
          "serverPort": null, 
          "icon": "", 
          "sort": "0", 
          "remark": "", 
          "status": "run"
      }
  ]')
function listToTree (resources) {
  console.log(resources)
}
console 命令行工具 X clear

                    
>
console