javascript - 在ReactJS中访问数组中的对象

标签 javascript arrays json reactjs

我目前在使用 React 解析一些 JSON 数据时遇到问题。这是我尝试使用的 JSON 数据:

[
  {
    "id": 3,
    "car_brand_id": 2,
    "car_model_id": 7,
    "youtube": "",
    "title": "New Ibiza range available in Sunderland & Durham - Pulman SEAT  ",
    "description": "Buy a new Ibiza from Pulman SEAT - Available to test drive in Sunderland & Durham",
    "slug": "ibiza",
    "published": 1,
    "news": 0,
    "published_at": "2016-07-05 09:16:04",
    "created_at": "2016-05-23 12:45:20",
    "updated_at": "2016-07-05 13:16:04",
    "offers": [
      {
        "id": 9,
        "car_page_id": 3,
        "car_trim_id": 15,
        "car_type_id": 1,
        "cap_code_id": 0,
        "car_image_id": 70,
        "derivative": "SC 1.2 TSI 90PS ",
        "car_position_id": 6,
        "youtube_code": "XDKSBXbIXV0",
        "terms": "This offer is for the from Pulman SEAT is based on PCP (personal contract plan). Valid for retail customers only. Vehicles to be registered and delivered before 30/09/16. Offer can be withdrawn at any time. It can also be extended. No other offers may be used in conjunction with the above detailed offer. At the beginning of the plan SEAT Financial services is the legal owner and provider of this PCP. At the end of the agreement there are 3 options: (i) Renew: Part exchange the vehicle (ii) Retain: Pay the Optional Final Payment to own the vehicle or (iii) Return the vehicle. *Payable with first payment. ** Payable with optional final payment. #4.4p per mile excess mileage charges apply. Further charges may be payable if vehicle is returned. Indemnities may be required. Subject to status. Available to over 18s in the UK only. Offer is subject to vehicle availability and may be varied or withdrawn at any time. Certain vehicles excluded- ask for full details. Finance providers may pay us for introducing you to them. We can introduce you to a limited number of lenders to assist with your purchase, who may pay us for introducing you to them. † £2,500 deposit contribution available on Ibiza SC FR 1.2 TSI 90PS when purchased on SEAT Solutions. ^ £671 Saving based on RRP. Images for illustration purposes only. ^^ One year’s insurance included at no extra cost from SEAT Insurance is available on all qualifying new Ibiza FR models only ordered from 1st July 2016 to 30th September 2016 and registered by 10th January 2017 for drivers 18 and over. Drivers under 18 are not eligible. May exclude Northern Ireland. Drivers aged 18-24 are required to share their driving style data with a telematics product. Available on Ibiza FR trim only. Other eligibility criteria apply. Go to www.seat.co.uk/free-insurance-offer for full terms and conditions. This offer may be extended, changed or removed at any point. SEAT Motor Insurance from SEAT Financial Services is arranged and administered by Carrot Risk Technologies Limited.",
        "status": 1,
        "created_at": "2016-07-04 15:08:03",
        "updated_at": "2016-07-19 14:03:46",
        "image": {
          "id": 70,
          "car_image_category_id": 7,
          "image_name": "Ibiza-FR-SC-Insurance",
          "name": "aa093fb987a0898588daa8825f90001443afc68d.png",
          "path": "img/imagedb/aa093fb987a0898588daa8825f90001443afc68d.png",
          "thumbnail_path": "img/imagedb/thumbs/tn-aa093fb987a0898588daa8825f90001443afc68d.png",
          "created_at": "2016-07-05 09:35:09",
          "updated_at": "2016-07-05 09:35:09"
        },
        "trim": {
          "id": 15,
          "car_model_id": 7,
          "name": "FR",
          "created_at": "2016-06-08 10:07:45",
          "updated_at": "2016-06-08 10:07:45"
        }
      }
    ],
    "model": {
      "id": 7,
      "brand_id": 2,
      "name": "Ibiza",
      "created_at": "2016-05-23 12:44:29",
      "updated_at": "2016-05-23 12:44:29"
    }
  },
  {
    "id": 6,
    "car_brand_id": 2,
    "car_model_id": 13,
    "youtube": "",
    "title": "New Mii range available in Sunderland & Durham - Pulman SEAT  ",
    "description": "Buy a new Mii from Pulman SEAT - Available to test drive in Sunderland & Durham",
    "slug": "mii",
    "published": 1,
    "news": 0,
    "published_at": "2016-07-05 05:51:57",
    "created_at": "2016-06-08 10:57:52",
    "updated_at": "2016-07-05 09:51:57",
    "offers": [
      {
        "id": 6,
        "car_page_id": 6,
        "car_trim_id": 21,
        "car_type_id": 1,
        "cap_code_id": null,
        "car_image_id": 60,
        "derivative": "3DR 1.0 60PS",
        "car_position_id": 2,
        "youtube_code": "",
        "terms": "At the end of the agreement there are three options: I) retain the vehicle: pay the optional final payment to own the vehicle; ii) return the vehicle; or iii) replace: part exchange the vehicle, subject to status. Available when purchased on Solutions Personal Contract Plan ordered until 30th September 2016. *Payable with first payment. ** Payable with optional final payment. Retail sales only. #4.4p per mile excess mileage charges apply. Further charges may be payable if vehicle is returned. Indemnities may be required. Subject to status. Available to over 18s in the UK only. Offer is subject to vehicle availability and may be varied or withdrawn at any time. † £1,800 deposit contribution available on Mii Design 1.0 3DR when purchased on SEAT Solutions. Finance providers may pay us for introducing you to them. We can introduce you to a limited number of lenders to assist with your purchase, who may pay us for introducing you to them. **Pulman SEAT price match guarantee is available on like for like new SEAT models with identical spec. A genuine quote must be provided within a 15-mile radius. images for illustration purposes only",
        "status": 1,
        "created_at": "2016-06-15 08:41:56",
        "updated_at": "2016-07-04 22:15:25",
        "image": {
          "id": 60,
          "car_image_category_id": 11,
          "image_name": "Mii-Design",
          "name": "dbecbdbc29234053e0bf8a09968ad991e7a17492.png",
          "path": "img/imagedb/dbecbdbc29234053e0bf8a09968ad991e7a17492.png",
          "thumbnail_path": "img/imagedb/thumbs/tn-dbecbdbc29234053e0bf8a09968ad991e7a17492.png",
          "created_at": "2016-07-04 12:34:07",
          "updated_at": "2016-07-04 12:34:07"
        },
        "trim": {
          "id": 21,
          "car_model_id": 13,
          "name": "Design",
          "created_at": "2016-06-14 09:17:10",
          "updated_at": "2016-06-14 09:17:10"
        }
      }
    ],
    "model": {
      "id": 13,
      "brand_id": 2,
      "name": "Mii",
      "created_at": "2016-06-08 10:54:21",
      "updated_at": "2016-06-08 10:54:21"
    }
  },
  {
    "id": 8,
    "car_brand_id": 2,
    "car_model_id": 11,
    "youtube": "",
    "title": "New SEAT Leon range available in Sunderland & Durham  - Pulman SEAT ",
    "description": "Buy a new SEAT Leon from Pulman SEAT - Available to test drive in Sunderland & Durham",
    "slug": "leon",
    "published": 1,
    "news": 0,
    "published_at": "2016-07-05 05:53:33",
    "created_at": "2016-07-04 08:38:32",
    "updated_at": "2016-07-05 09:53:33",
    "offers": [
      {
        "id": 21,
        "car_page_id": 8,
        "car_trim_id": 35,
        "car_type_id": 1,
        "cap_code_id": null,
        "car_image_id": 50,
        "derivative": "5DR 1.2 TSI 110PS",
        "car_position_id": 19,
        "youtube_code": "",
        "terms": "At the end of the agreement there are three options: i) retain the vehicle: pay the optional final payment to own the vehicle; ii) return the vehicle; or iii) replace: part exchange the vehicle, subject to status. Available when purchased on Solutions Personal Contract Plan until 30th September 2016. Retail sales only. *Payable with first payment. ** Payable with optional final payment. #7.2p per mile excess mileage charges apply. Further charges may be payable if vehicle is returned. Indemnities may be required. Subject to status. Available to over 18s in the UK only. Offer is subject to vehicle availability and may be varied or withdrawn at any time. Certain vehicles excluded- ask for full details. † £2,000 deposit contributions available when purchased on SEAT Personal Contract Plan. Retail Sales Only. Finance providers may pay us for introducing you to them. We can introduce you to a limited number of lenders to assist with your purchase, who may pay us for introducing you to them. Images for illustrative purposes only. ",
        "status": 1,
        "created_at": "2016-07-05 08:29:28",
        "updated_at": "2016-07-19 14:03:46",
        "image": {
          "id": 50,
          "car_image_category_id": 12,
          "image_name": "Leon-SE-5DR",
          "name": "184484219879badbb5dab51b7421203c2bc16fa0.png",
          "path": "img/imagedb/184484219879badbb5dab51b7421203c2bc16fa0.png",
          "thumbnail_path": "img/imagedb/thumbs/tn-184484219879badbb5dab51b7421203c2bc16fa0.png",
          "created_at": "2016-07-04 12:25:48",
          "updated_at": "2016-07-04 12:25:48"
        },
        "trim": {
          "id": 35,
          "car_model_id": 11,
          "name": "SE Dynamic",
          "created_at": "2016-06-14 09:51:20",
          "updated_at": "2016-06-14 09:51:20"
        }
      }
    ],
    "model": {
      "id": 11,
      "brand_id": 2,
      "name": "Leon",
      "created_at": "2016-06-08 10:06:29",
      "updated_at": "2016-06-08 10:06:29"
    }
  },
  {
    "id": 9,
    "car_brand_id": 2,
    "car_model_id": 14,
    "youtube": "",
    "title": "Lorem",
    "description": "Lorem",
    "slug": "ibiza-st",
    "published": 0,
    "news": 0,
    "published_at": "2016-07-04 11:38:48",
    "created_at": "2016-07-04 13:05:29",
    "updated_at": "2016-07-04 15:38:48",
    "offers": [],
    "model": {
      "id": 14,
      "brand_id": 2,
      "name": "Ibiza ST",
      "created_at": "2016-06-08 10:54:53",
      "updated_at": "2016-06-08 10:54:53"
    }
  },
  {
    "id": 10,
    "car_brand_id": 2,
    "car_model_id": 15,
    "youtube": "",
    "title": "New Leon ST range available in Sunderland & Durham - Pulman SEAT  ",
    "description": "Buy a new SEAT Leon ST from Pulman SEAT - Available to test drive in Sunderland & Durham",
    "slug": "leon-st",
    "published": 1,
    "news": 0,
    "published_at": "2016-07-05 05:54:09",
    "created_at": "2016-07-04 13:23:23",
    "updated_at": "2016-07-05 09:54:09",
    "offers": [
      {
        "id": 22,
        "car_page_id": 10,
        "car_trim_id": 48,
        "car_type_id": 1,
        "cap_code_id": null,
        "car_image_id": 53,
        "derivative": "5DR 1.2 TSI 110PS",
        "car_position_id": 23,
        "youtube_code": "",
        "terms": "At the end of the agreement there are three options: i) retain the vehicle: pay the optional final payment to own the vehicle; ii) return the vehicle; or iii) replace: part exchange the vehicle, subject to status. Available when purchased on Solutions Personal Contract Plan until 30th September 2016. Retail sales only. *Payable with first payment. ** Payable with optional final payment. #7.2p per mile excess mileage charges apply. Further charges may be payable if vehicle is returned. Indemnities may be required. Subject to status. Available to over 18s in the UK only. Offer is subject to vehicle availability and may be varied or withdrawn at any time. Certain vehicles excluded- ask for full details. † £2,000 deposit contributions available when purchased on SEAT Personal Contract Plan. Retail Sales Only. Finance providers may pay us for introducing you to them. We can introduce you to a limited number of lenders to assist with your purchase, who may pay us for introducing you to them. Images for illustrative purposes only.",
        "status": 1,
        "created_at": "2016-07-05 08:38:51",
        "updated_at": "2016-07-19 14:15:41",
        "image": {
          "id": 53,
          "car_image_category_id": 12,
          "image_name": "Leon-ST-SE",
          "name": "c743dc09fc1b24c1fac866baf6e3fe3f98f3e6af.png",
          "path": "img/imagedb/c743dc09fc1b24c1fac866baf6e3fe3f98f3e6af.png",
          "thumbnail_path": "img/imagedb/thumbs/tn-c743dc09fc1b24c1fac866baf6e3fe3f98f3e6af.png",
          "created_at": "2016-07-04 12:25:49",
          "updated_at": "2016-07-04 12:25:49"
        },
        "trim": {
          "id": 48,
          "car_model_id": 15,
          "name": "SE Dynamic",
          "created_at": "2016-06-14 10:39:16",
          "updated_at": "2016-06-14 10:39:16"
        }
      }
    ],
    "model": {
      "id": 15,
      "brand_id": 2,
      "name": "Leon ST",
      "created_at": "2016-06-08 10:55:21",
      "updated_at": "2016-06-08 10:55:21"
    }
  },
  {
    "id": 11,
    "car_brand_id": 2,
    "car_model_id": 16,
    "youtube": "",
    "title": " New SEAT Leon Cupra range available in Sunderland - Pulman SEAT ",
    "description": "Buy a new SEAT Leon Cupra from Pulman SEAT - Available to test drive in Sunderland & Durham",
    "slug": "leon-cupra",
    "published": 1,
    "news": 0,
    "published_at": "2016-07-05 05:55:06",
    "created_at": "2016-07-04 13:27:04",
    "updated_at": "2016-07-05 09:55:06",
    "offers": [
      {
        "id": 11,
        "car_page_id": 11,
        "car_trim_id": 39,
        "car_type_id": 1,
        "cap_code_id": null,
        "car_image_id": 67,
        "derivative": "SC 2.0 TSI 290PS ",
        "car_position_id": 11,
        "youtube_code": "",
        "terms": "At the end of the agreement there are three options: I) retain the vehicle: pay the optional final payment to own the vehicle; ii) return the vehicle; or iii) replace: part exchange the vehicle, subject to status. Available when purchased on Solutions Personal Contract Plan on vehicles ordered until 30th September 2016. Retail sales only. *Payable with first payment. ** Payable with optional final payment. #7.2p per mile excess mileage charges apply. Further charges may be payable if vehicle is returned. Indemnities may be required. Subject to status. Available to over 18s in the UK only. Offer is subject to vehicle availability and may be varied or withdrawn at any time. Certain vehicles excluded- ask for full details. † £2,500 deposit contribution available when purchased with SEAT finance. * Finance providers may pay us for introducing you to them. We can introduce you to a limited number of lenders to assist with your purchase, who may pay us for introducing you to them. Images for illustrative purposes only. Images for illustration purposes only.",
        "status": 1,
        "created_at": "2016-07-04 15:39:03",
        "updated_at": "2016-07-19 14:03:46",
        "image": {
          "id": 67,
          "car_image_category_id": 16,
          "image_name": "Leon-Cupra",
          "name": "860d4b8e32224ccabe5cf4c2b78424b0fccbf0ea.png",
          "path": "img/imagedb/860d4b8e32224ccabe5cf4c2b78424b0fccbf0ea.png",
          "thumbnail_path": "img/imagedb/thumbs/tn-860d4b8e32224ccabe5cf4c2b78424b0fccbf0ea.png",
          "created_at": "2016-07-05 09:22:40",
          "updated_at": "2016-07-05 09:22:40"
        },
        "trim": {
          "id": 39,
          "car_model_id": 16,
          "name": "290",
          "created_at": "2016-06-14 10:16:19",
          "updated_at": "2016-06-14 10:16:19"
        }
      }
    ],
    "model": {
      "id": 16,
      "brand_id": 2,
      "name": "Leon Cupra",
      "created_at": "2016-06-08 10:55:28",
      "updated_at": "2016-06-08 10:55:28"
    }
  },
  {
    "id": 12,
    "car_brand_id": 2,
    "car_model_id": 17,
    "youtube": "",
    "title": " New SEAT Leon X-PERIENCE range available in Sunderland - Pulman SEAT ",
    "description": "Buy a new SEAT Leon X-PERIENCE from Pulman SEAT - Available to test drive in Sunderland & Durham",
    "slug": "leon-x-perience",
    "published": 1,
    "news": 0,
    "published_at": "2016-07-05 05:56:46",
    "created_at": "2016-07-04 13:40:32",
    "updated_at": "2016-07-05 09:56:46",
    "offers": [
      {
        "id": 23,
        "car_page_id": 12,
        "car_trim_id": 37,
        "car_type_id": 1,
        "cap_code_id": 175,
        "car_image_id": 54,
        "derivative": "2.0 TDI 150PS",
        "car_position_id": 24,
        "youtube_code": "",
        "terms": "At the end of the agreement there are three options: i) retain the vehicle: pay the optional final payment to own the vehicle; ii) return the vehicle; or iii) replace: part exchange the vehicle, subject to status. Available when purchased on Solutions Personal Contract Plan until 30th September 2016. Retail sales only. *Payable with first payment. ** Payable with optional final payment. #7.2p per mile excess mileage charges apply. Further charges may be payable if vehicle is returned. Indemnities may be required. Subject to status. Available to over 18s in the UK only. Offer is subject to vehicle availability and may be varied or withdrawn at any time. Certain vehicles excluded- ask for full details. † £2,000 deposit contributions available when purchased on SEAT Personal Contract Plan. Retail Sales Only. Finance providers may pay us for introducing you to them. We can introduce you to a limited number of lenders to assist with your purchase, who may pay us for introducing you to them. Images for illustrative purposes only. ^^ This information should be used for illustration purposes only. Standard EU Test figures for comparison purposes, may not reflect real driving results.",
        "status": 1,
        "created_at": "2016-07-05 09:43:11",
        "updated_at": "2016-07-19 14:15:41",
        "image": {
          "id": 54,
          "car_image_category_id": 12,
          "image_name": "Leon-X-Perience",
          "name": "e3e791f870ef57ade77d1f04436d423ac9ae5755.png",
          "path": "img/imagedb/e3e791f870ef57ade77d1f04436d423ac9ae5755.png",
          "thumbnail_path": "img/imagedb/thumbs/tn-e3e791f870ef57ade77d1f04436d423ac9ae5755.png",
          "created_at": "2016-07-04 12:25:50",
          "updated_at": "2016-07-04 12:25:50"
        },
        "trim": {
          "id": 37,
          "car_model_id": 17,
          "name": "SE",
          "created_at": "2016-06-14 10:11:43",
          "updated_at": "2016-06-14 10:11:43"
        }
      }
    ],
    "model": {
      "id": 17,
      "brand_id": 2,
      "name": "Leon X-PERIENCE",
      "created_at": "2016-06-08 10:55:54",
      "updated_at": "2016-06-08 10:55:54"
    }
  },
  {
    "id": 13,
    "car_brand_id": 2,
    "car_model_id": 18,
    "youtube": "",
    "title": "New SEAT Toledo range available in Sunderland - Pulman SEAT ",
    "description": "Buy a new SEAT Toledo from Pulman SEAT - Available to test drive in Sunderland & Durham",
    "slug": "toledo",
    "published": 1,
    "news": 0,
    "published_at": "2016-07-05 05:56:34",
    "created_at": "2016-07-04 13:40:48",
    "updated_at": "2016-07-05 09:56:34",
    "offers": [
      {
        "id": 19,
        "car_page_id": 13,
        "car_trim_id": 50,
        "car_type_id": 1,
        "cap_code_id": 197,
        "car_image_id": 63,
        "derivative": "1.4 TDI Ecomotive SE",
        "car_position_id": 18,
        "youtube_code": "",
        "terms": "At the end of the agreement there are three options: I) retain the vehicle: pay the optional final payment to own the vehicle; ii) return the vehicle; or iii) replace: part exchange the vehicle, subject to status. Available when purchased on Solutions Personal Contract Plan on vehicles ordered until 30th September 2016. Retail sales only. *Payable with first payment. ** Payable with optional final payment. #7.2p per mile excess mileage charges apply. Further charges may be payable if vehicle is returned. Indemnities may be required. Subject to status. Available to over 18s in the UK only. Offer is subject to vehicle availability and may be varied or withdrawn at any time. Certain vehicles excluded- ask for full details. † £3,250 deposit contribution available on when purchased on SEAT Solutions. Finance providers may pay us for introducing you to them. We can introduce you to a limited number of lenders to assist with your purchase, who may pay us for introducing you to them.  Images for illustrative purposes only. ^^ This information should be used for illustration purposes only. Standard EU Test figures for comparison purposes, may not reflect real driving results.",
        "status": 1,
        "created_at": "2016-07-05 08:17:55",
        "updated_at": "2016-07-19 14:03:46",
        "image": {
          "id": 63,
          "car_image_category_id": 14,
          "image_name": "Toledo-Style-Advanced",
          "name": "f2ba78e24b7f9286e5c4b37da716e491a99f2d23.png",
          "path": "img/imagedb/f2ba78e24b7f9286e5c4b37da716e491a99f2d23.png",
          "thumbnail_path": "img/imagedb/thumbs/tn-f2ba78e24b7f9286e5c4b37da716e491a99f2d23.png",
          "created_at": "2016-07-04 12:41:54",
          "updated_at": "2016-07-04 12:41:54"
        },
        "trim": {
          "id": 50,
          "car_model_id": 18,
          "name": "SE",
          "created_at": "2016-06-14 10:49:09",
          "updated_at": "2016-06-14 10:49:09"
        }
      }
    ],
    "model": {
      "id": 18,
      "brand_id": 2,
      "name": "Toledo",
      "created_at": "2016-06-08 10:56:11",
      "updated_at": "2016-06-08 10:56:11"
    }
  },
  {
    "id": 14,
    "car_brand_id": 2,
    "car_model_id": 19,
    "youtube": "",
    "title": "New SEAT Alhambra range available in Sunderland - Pulman SEAT ",
    "description": "Buy a new SEAT Alhambra from Pulman SEAT - Available to test drive in Sunderland & Durham",
    "slug": "alhambra",
    "published": 1,
    "news": 0,
    "published_at": "2016-07-05 05:57:49",
    "created_at": "2016-07-04 13:41:03",
    "updated_at": "2016-07-05 09:57:49",
    "offers": [
      {
        "id": 15,
        "car_page_id": 14,
        "car_trim_id": 54,
        "car_type_id": 1,
        "cap_code_id": 3,
        "car_image_id": 64,
        "derivative": "2.0 TDI CR 150PS ",
        "car_position_id": 14,
        "youtube_code": "",
        "terms": "At the end of the agreement there are three options: I) retain the vehicle: pay the optional final payment to own the vehicle; ii) return the vehicle; or iii) replace: part exchange the vehicle, subject to status. Available when purchased on Solutions Personal Contract Plan. Retail sales only. Offer available for vehicles ordered before 30th September 2016. *Payable with first payment. ** Payable with optional final payment. #7.2p per mile excess mileage charges apply. Further charges may be payable if vehicle is returned. Indemnities may be required. Subject to status. Available to over 18s in the UK only. Offer is subject to vehicle availability and may be varied or withdrawn at any time. Certain vehicles excluded- ask for full details. † £2,000 deposit contribution available on SEAT Alhambra when purchased on SEAT Solutions. Finance providers may pay us for introducing you to them. We can introduce you to a limited number of lenders to assist with your purchase, who may pay us for introducing you to them.  ^^ This information should be used for illustration purposes only. Standard EU Test figures for comparison purposes, may not reflect real driving results. Images for illustrative purposes only.",
        "status": 1,
        "created_at": "2016-07-04 15:55:00",
        "updated_at": "2016-07-19 14:03:46",
        "image": {
          "id": 64,
          "car_image_category_id": 15,
          "image_name": "Alhambra",
          "name": "d6a0039805cdb91732992799ef0d52892767a36b.png",
          "path": "img/imagedb/d6a0039805cdb91732992799ef0d52892767a36b.png",
          "thumbnail_path": "img/imagedb/thumbs/tn-d6a0039805cdb91732992799ef0d52892767a36b.png",
          "created_at": "2016-07-04 12:44:19",
          "updated_at": "2016-07-04 12:44:19"
        },
        "trim": {
          "id": 54,
          "car_model_id": 19,
          "name": "SE",
          "created_at": "2016-06-14 10:55:55",
          "updated_at": "2016-06-14 10:55:55"
        }
      }
    ],
    "model": {
      "id": 19,
      "brand_id": 2,
      "name": "Alhambra",
      "created_at": "2016-06-08 10:56:23",
      "updated_at": "2016-06-08 10:56:23"
    }
  },
  {
    "id": 15,
    "car_brand_id": 2,
    "car_model_id": 20,
    "youtube": "mJTPmbuxwqQ",
    "title": "New ATECA range available in Sunderland & Durham - Pulman SEAT  ",
    "description": "Buy a new SEAT ATECA from Pulman SEAT - Available to test drive in Sunderland & Durham",
    "slug": "ateca",
    "published": 1,
    "news": 0,
    "published_at": "2016-07-07 08:22:04",
    "created_at": "2016-07-07 09:16:52",
    "updated_at": "2016-07-07 12:22:04",
    "offers": [
      {
        "id": 26,
        "car_page_id": 15,
        "car_trim_id": 62,
        "car_type_id": 1,
        "cap_code_id": null,
        "car_image_id": 80,
        "derivative": "1.0 TSI 115PS",
        "car_position_id": 25,
        "youtube_code": "",
        "terms": "At the end of the agreement there are three options: I) retain the vehicle: pay the optional final payment to own the vehicle; ii) return the vehicle; or iii) replace: part exchange the vehicle, subject to status. Available when purchased on Solutions Personal Contract Plan ordered until 30th September 2016. *Payable with first payment. ** Payable with optional final payment. Retail sales only. #4.4p per mile excess mileage charges apply. Further charges may be payable if vehicle is returned. Indemnities may be required. Subject to status. Available to over 18s in the UK only. Offer is subject to vehicle availability and may be varied or withdrawn at any time. Finance providers may pay us for introducing you to them. We can introduce you to a limited number of lenders to assist with your purchase, who may pay us for introducing you to them. ",
        "status": 1,
        "created_at": "2016-07-07 12:13:50",
        "updated_at": "2016-07-19 14:15:41",
        "image": {
          "id": 80,
          "car_image_category_id": 17,
          "image_name": "Ateca-First",
          "name": "df14d12b1016b885cf63a47900886322d1c189f9.png",
          "path": "img/imagedb/df14d12b1016b885cf63a47900886322d1c189f9.png",
          "thumbnail_path": "img/imagedb/thumbs/tn-df14d12b1016b885cf63a47900886322d1c189f9.png",
          "created_at": "2016-07-07 09:44:21",
          "updated_at": "2016-07-07 09:44:21"
        },
        "trim": {
          "id": 62,
          "car_model_id": 20,
          "name": "First Edition",
          "created_at": "2016-07-07 09:06:31",
          "updated_at": "2016-07-07 09:06:31"
        }
      }
    ],
    "model": {
      "id": 20,
      "brand_id": 2,
      "name": "Ateca",
      "created_at": "2016-07-07 09:04:36",
      "updated_at": "2016-07-07 09:04:36"
    }
  }
]

我可以使用大部分数据,但是当我尝试访问 "offers" 数组中的对象时,它不会提取任何数据。

目前我可以将数据拉入我的组件中,如下所示:

{props.vehicle.model.name}

但是,如果我尝试像这样从数组中提取数据:

{props.vehicle.offers.derivative}

没有数据被拉到前端,知道如何访问该数据吗?

谢谢,尼克

最佳答案

offersObjectsArray,首先需要通过索引获取 Array 元素,然后获取 对象的属性

props.vehicle.offers[0].derivative

更新

您收到此错误(TypeError:无法读取未定义的属性“派生”),因为您的数据中 offers 为空Array,例如 { id: 9 },有空 offers。如果 offers 为空 Array offers[0] 返回 undefined,当您尝试获取属性 .derivative 时,它会抛出错误,因为 undefined 没有任何属性。,您可以添加条件来检查 offers 是否包含元素 - Example

关于javascript - 在ReactJS中访问数组中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38524580/

相关文章:

javascript - 使用 JS 更改没有 id 或 class 的内联 CSS

javascript - 如何使用jquery获取json数据

javascript - 我应该如何在 javascript 中将复杂对象持久化为字符串

JavaScript 无法在 Windows Server 2003 上运行

javascript - 操作 JSON 数组数据

javascript - findIndex() 返回 -1 而不是正确的索引号

c - C 中的数字螺旋,代码不起作用

JavaScript - 'Normalize' 数组索引

java - 扩展谷歌库方法的最佳方式

javascript - 请解释一下这个java脚本代码行