我从一个包含 currentDataResult 和 pastDataResult 的 api 返回一个对象数组。
[
{
"sectionCurrentDataResult": [
{
"section_id": 14785,
"subdivision_name": "Stratton Woods",
},
{
"section_id": 14790,
"subdivision_name": "Stratton Woods",
},
{
"section_id": 14791,
"subdivision_name": "Stratton Woods"
},
{
"section_id": 14792,
"subdivision_name": "Stratton Woods"
},
{
"section_id": 14781,
"subdivision_name": "Stratton Woods"
},
{
"section_id": 14786,
"subdivision_name": "Stratton Woods"
},
{
"section_id": 14787,
"subdivision_name": "Stratton Woods"
},
{
"section_id": 14788,
"subdivision_name": "Stratton Woods"
},
{
"section_id": 14782,
"subdivision_name": "Stratton Woods"
},
{
"section_id": 14783,
"subdivision_name": "Stratton Woods"
},
{
"section_id": 14784,
"subdivision_name": "Stratton Woods"
},
{
"section_id": 5326,
"subdivision_id": 1439,
"subdivision_name": "Stratton Woods"
}
]
},
{
"sectionPastDataResult": [
{
"section_id": 5326,
"price_min": 177,
"price_max": 235
},
{
"section_id": 14785,
"price_min": 190,
"price_max": 220
},
{
"section_id": 14786,
"price_min": 238,
"price_max": 292
},
{
"section_id": 14788,
"price_min": 186,
"price_max": 205
},
{
"section_id": 14790,
"price_min": 150,
"price_max": 269
},
{
"section_id": 14783,
"price_min": 150,
"price_max": 260
},
{
"section_id": 14787,
"price_min": 90,
"price_max": 90
},
{
"section_id": 14792,
"price_min": 177,
"price_max": 235
},
{
"section_id": 14791,
"price_min": 145,
"price_max": 221
},
{
"section_id": 14784,
"price_min": 148,
"price_max": 186
},
{
"section_id": 14781,
"price_min": 155,
"price_max": 200
},
{
"section_id": 14782,
"price_min": 150,
"price_max": 170
}
]
}
]
我需要将匹配的 pastDataObject(by section_id) 对象作为嵌套数组推送到 currentDataResult 对象中。这就是它需要的样子
"sectionCurrentDataResult": [
{
"section_id": 14785,
"subdivision_name": "Stratton Woods",
"sectionHistory":[{
"section_id": 14785,
"price_min": 190,
"price_max": 220
}]
},
{
"section_id": 14790,
"subdivision_name": "Stratton Woods",
"sectionHistory":[{
"section_id": 14790,
"price_min": 150,
"price_max": 269
}]
},
etc....
]
我创建了一个服务,它同时获取当前和过去的数据结果,并重新排序过去的数据结果以匹配当前。我需要帮助的是将过去的数据数组推入当前的数据对象。现在它错误地将整个过去的数据数组推入当前数据数组的第一个对象中。我已经用我的代码设置了一个 plunker。
app.controller('MainCtrl', function($scope,bigEnchilada,inputHistorySvc) {
for (var i = 0; i < bigEnchilada[0].sectionCurrentDataResult.length; i++) {
bigEnchilada[0].sectionCurrentDataResult[i].sectionHistory = inputHistorySvc.historyInputs(bigEnchilada);
}
$scope.sections = bigEnchilada[0].sectionCurrentDataResult;
});