我有一些JSON和想回一些嵌套的對象,這是JSON:如何返回嵌套數組與lodash?
{
"existingPackage": {
"primaryBundle": {
"id": "2031",
"serviceId": "114297251",
"name": "TV - Entertainment, Drama, Movies",
"products": [
{
"name": "Entertainment",
"id": "100",
"price": 2600,
"gifted": false
},
{
"name": "Drama",
"id": "104",
"price": 2000,
"gifted": false,
"swappableProducts": [
{
"name": "Sport",
"id": "107",
"price": 2500,
"gifted": false
}
]
},
{
"name": "Movies",
"id": "105",
"price": 2000,
"gifted": false,
"swappableProducts": [
{
"name": "Sport",
"id": "107",
"price": 2500,
"gifted": false
}
]
}
]
}
}
}
的目標是從有swappableProducts財產,並有一定的id productsarray返回唯一項目。 因此,例如,當我的productId參數= 105,然後我想回:
{
"name": "Movies",
"id": "105",
"price": 2000,
"gifted": false,
"swappableProducts": [
{
"name": "Sport",
"id": "107",
"price": 2500,
"gifted": false
}
]
}
}
如何我lodash返回此?
可能重複的[如何使用lodash從數組中找到並返回一個對象?](http://stackoverflow.com/questions/31054021/how-to-use-lodash-to-find-and-return-一個對象-從陣列) – Rajesh