如何使用lodash从json返回childobject属性?

时间:2017-02-25 06:26:36

标签: javascript lodash

我正在使用lodash并拥有这个json对象,我想要返回的属性是嵌套数组,即swappableProducts:

{
  "existing": {
    "hasPlatinum": false,
    "primaryBundle": {
      "id": "2008",
      "serviceId": "1",
      "name": "TV - Entertainment, Sport",
      "products": [
        {
          "name": "Entertainment",
          "id": "100",
          "price": 2600,
          "gifted": false
        },
        {
          "name": "Sport",
          "id": "107",
          "price": 2500,
          "gifted": false,
          "swappableProducts": [
            {
              "name": "Movies",
              "id": "105",
              "price": 2000,
              "gifted": false
            },
            {
              "name": "Games",
              "id": "10",
              "price": 1000,
              "gifted": false
            }
          ]
        }
      ]
    }
  }

我试图像这样返回swappableProducts数组:

 _.get(userObject, 'existing.primaryBundle.products[1].swappableProducts');

但它不会退货。我怎么能这样做?

0 个答案:

没有答案