如何使用Redux React编写异步树结构?

时间:2019-05-20 19:19:17

标签: react-redux

我想开发一种树结构,该结构在页面上仅加载第一级子级,如果单击其中的任何子级,如果它们也有子级,则它们也将加载,依此类推...该树可以深入许多级别。

这是我用来在页面加载时加载的示例数据:

容器数据

{
      "code": "string",
    "message": "string",
    "data": {
      "comments": "string",
      "containerId": 412,
      "createdBy": "string",
      "createdDate": "2019-05-09T18:23:59.582Z",
      "discoveryAgentId": 0,
      "inheritedDiscoveryAgent": "string",
      "modifiedBy": "string",
      "modifiedDate": "2019-05-09T18:23:59.582Z",
      "name": "CRAN",
      "parentId": 0,
      "planId": 0,
      "typeId": 0,
      "depth":0,
       "children":[{
          "comments": "string",
          "containerId": 231,
          "createdBy": "string",
          "createdDate": "2019-05-09T18:23:59.582Z",
          "discoveryAgentId": 0,
          "inheritedDiscoveryAgent": "string",
          "modifiedBy": "string",
          "modifiedDate": "2019-05-09T18:23:59.582Z",
          "name": "South Central",
          "parentId": 0,
          "planId": 0,
          "typeId": 0,
          "depth":1,
          "hasChildren": false
          },{
          "comments": "string",
          "containerId": 324,
          "createdBy": "string",
          "createdDate": "2019-05-09T18:23:59.582Z",
          "discoveryAgentId": 0,
          "inheritedDiscoveryAgent": "string",
          "modifiedBy": "string",
          "modifiedDate": "2019-05-09T18:23:59.582Z",
          "name": "North East",
          "parentId": 0,
          "planId": 0,
          "typeId": 0,
          "hasChildren": true
          },{
          "comments": "string",
          "containerId": 65,
          "createdBy": "string",
          "createdDate": "2019-05-09T18:23:59.582Z",
          "discoveryAgentId": 0,
          "inheritedDiscoveryAgent": "string",
          "modifiedBy": "string",
          "modifiedDate": "2019-05-09T18:23:59.582Z",
          "name": "South East",
          "parentId": 0,
          "planId": 0,
          "typeId": 0,
          "hasChildren": false
          },{
          "comments": "string",
          "containerId": 41,
          "createdBy": "string",
          "createdDate": "2019-05-09T18:23:59.582Z",
          "discoveryAgentId": 0,
          "inheritedDiscoveryAgent": "string",
          "modifiedBy": "string",
          "modifiedDate": "2019-05-09T18:23:59.582Z",
          "name": "East West",
          "parentId": 0,
          "planId": 0,
          "typeId": 0,
          "hasChildren": true
        }]
    }

以下是一些子样本数据

"children":[{
            "comments": "string",
            "containerId": 231,
            "createdBy": "string",
            "createdDate": "2019-05-09T18:23:59.582Z",
            "discoveryAgentId": 0,
            "inheritedDiscoveryAgent": "string",
            "modifiedBy": "string",
            "modifiedDate": "2019-05-09T18:23:59.582Z",
            "name": "Child 1",
            "parentId": 0,
            "planId": 0,
            "typeId": 0,
            "depth":2,
            "hasChildren": false
            },{
            "comments": "string",
            "containerId": 324,
            "createdBy": "string",
            "createdDate": "2019-05-09T18:23:59.582Z",
            "discoveryAgentId": 0,
            "inheritedDiscoveryAgent": "string",
            "modifiedBy": "string",
            "modifiedDate": "2019-05-09T18:23:59.582Z",
            "name": "Child 2",
            "parentId": 0,
            "planId": 0,
            "typeId": 0,
            "depth":2,
            "hasChildren": true
            },{
            "comments": "string",
            "containerId": 65,
            "createdBy": "string",
            "createdDate": "2019-05-09T18:23:59.582Z",
            "discoveryAgentId": 0,
            "inheritedDiscoveryAgent": "string",
            "modifiedBy": "string",
            "modifiedDate": "2019-05-09T18:23:59.582Z",
            "name": "Child 3",
            "parentId": 0,
            "planId": 0,
            "typeId": 0,
            "depth":2,
            "hasChildren": false
            },{
            "comments": "string",
            "containerId": 41,
            "createdBy": "string",
            "createdDate": "2019-05-09T18:23:59.582Z",
            "discoveryAgentId": 0,
            "inheritedDiscoveryAgent": "string",
            "modifiedBy": "string",
            "modifiedDate": "2019-05-09T18:23:59.582Z",
            "name": "Child 4",
            "parentId": 0,
            "planId": 0,
            "typeId": 0,
            "depth":2,
            "hasChildren": true
        }]

在此页面上,是我试图实现的目标的“扩展加载” 示例。我无法在该页面上使用该组件,但是我想要该功能。请参阅下面我要实现的链接。

https://2x.ant.design/components/tree/

0 个答案:

没有答案