0
我有以下JSON響應:如何映射嵌套對象數組?
{
"fruits": [
{
"name": "apple",
"prices": [
{
"small": 2,
"medium": 3,
"large": 5
}
]
},
{
"name": "banana",
"prices": [
{
"small": 1,
"medium": 3,
"large": 4
}
]
}
]
}
我想把它映射到一個新的數組,這樣我就可以得到每個水果的「price.small」:
$scope.new_data = $scope.fruits.map(function(fruit){
return {
name: fruit.name,
price_small: fruit.prices.small
};
});
但它的不工作