Home > database >  how can i listing component nestedly?
how can i listing component nestedly?

Time:03-18

[
  {
    "id": 0.5256669517010202,
    "color": false,
    "selected": false,
    "name": "",
    "type": "",
    "label": "",
    "fieldName": "",
    "required": "",
    "validation": ""
  },
  {
    "id": 0.5901705709044824,
    "color": false,
    "selected": false,
    "type": [
      {
        "id": 0.30332161644408817,
        "color": true,
        "selected": false,
        "name": "",
        "type": "",
        "label": "",
        "fieldName": "",
        "required": "",
        "validation": ""
      },
      {
        "id": 0.5423422175390649,
        "color": true,
        "selected": false,
        "name": "",
        "type": "",
        "label": "",
        "fieldName": "",
        "required": "",
        "validation": ""
      },
      {
        "id": 0.959208393000617,
        "color": true,
        "selected": false,
        "name": "",
        "type": "",
        "label": "",
        "fieldName": "",
        "required": "",
        "validation": ""
      }
    ],
    "label": "",
    "fieldName": "",
    "required": "",
    "validation": ""
  },
  {
    "id": 0.5933110602496239,
    "color": false,
    "selected": false,
    "type": "",
    "label": "",
    "fieldName": "",
    "required": "",
    "validation": ""
  }
]

CodePudding user response:

I think you should use Map method

const data = [
  {
    "id": 0.5256669517010202,
    "color": false,
    "selected": false,
    "name": "",
    "type": "",
    "label": "",
    "fieldName": "",
    "required": "",
    "validation": ""
  },
  {
    "id": 0.5901705709044824,
    "color": false,
    "selected": false,
    "type": [
      {
        "id": 0.30332161644408817,
        "color": true,
        "selected": false,
        "name": "",
        "type": "",
        "label": "",
        "fieldName": "",
        "required": "",
        "validation": ""
      },
      {
        "id": 0.5423422175390649,
        "color": true,
        "selected": false,
        "name": "",
        "type": "",
        "label": "",
        "fieldName": "",
        "required": "",
        "validation": ""
      },
      {
        "id": 0.959208393000617,
        "color": true,
        "selected": false,
        "name": "",
        "type": "",
        "label": "",
        "fieldName": "",
        "required": "",
        "validation": ""
      }
    ],
    "label": "",
    "fieldName": "",
    "required": "",
    "validation": ""
  },
  {
    "id": 0.5933110602496239,
    "color": false,
    "selected": false,
    "type": "",
    "label": "",
    "fieldName": "",
    "required": "",
    "validation": ""
  }
]

data.map((item) => item.id)

CodePudding user response:

Just Try! You should declared attribute type as Array always!

data.map(Item => (
  Item.type.map(Item => ())
))
  • Related