我的JSON
{
"RECORDS": [
{
"Id": 23040035705987,
"arriveddate": "2015/04/24",
"expirationDate": null,
"replacedDate": null,
"processDate": "2015/04/24"
},
{
"Id": 23070041800654,
"arriveddate": "2015/04/24",
"expirationDate": null,
"replacedDate": null,
"processDate": "2015/04/27"
},
{
"Id": 23040035705984,
"arriveddate": "2015/04/24",
"expirationDate": null,
"replacedDate": null,
"processDate": "2015/04/24"
},
{
"Id": 23040035705983,
"arriveddate": "2015/04/24",
"expirationDate": null,
"replacedDate": null,
"processDate": "2015/04/24"
}
],
}
预期对象
{
"processDate": [
"2015/04/24",
"2015/04/27"
],
"Id": [
[
23040035705983,
23040035705984,
23040035705987
],
[
23070041800654
]
]
}
我需要根据进程日期进行映射,就像在我的预期对象中一样,我有两个日期,这是我所有JSON的唯一日期,在下一个ID中我有每个id属于相应的进程日期现在我已经能够获得独特的过程日期,但在下一个我无法做到的ID中,请您提供一个示例,了解我应如何循环以实现相同的角度
答案 0 :(得分:0)
您可以使用两个嵌套的forEach循环。
angular.forEach(obj.processDate, function(processValue, processIndex,date) {
angular.forEach(obj2.RECORDS, function (recordValue, recordIndex,records) {
if (processValue === recordValue["processDate"]) {
if (!obj["Id"][processIndex]) {
obj["Id"][processIndex]=[];
}
obj["Id"][processIndex].push(recordValue["Id"]);
});
});
}