1
阵列我有这样看对象的数组:创建统计出与AngularJS
[
{
"date":"20/11/2014",
"time":"17.54.39",
"car":"369",
"driver":"Jenny",
"from":"Luna House",
"destination":"James Hotel",
"pax":"3",
"comment":"",
"commenttime":"",
"arrival":"17.54.45",
"inserted":true,
"cancelled":"",
"duration":"00:00:06"
},
{
"date":"23/11/2014",
"time":"10.54.39",
"car":"210",
"driver":"David",
"from":"Office",
"destination":"Airport",
"pax":"3",
"comment":"",
"commenttime":"",
"arrival":"11.01.45",
"inserted":true,
"cancelled":"",
"duration":"00:07:06"
}
]
我所试图做的是要能够提供统计出的数据的阵列。事情是这样的:
阵列中的每个对象都是一趟,车是“汽车:代码”和时间的道路上是一切的总和“时间:” 12:34:56" (是这样的momentJS对象)
到目前为止,我已经能够创建一个对象,使用下面的代码,列出了所有独特的几个月。
var monthDict = {};
angular.forEach($scope.recordlist, function(record) {
var month = moment(record.date, 'DD-MM-YYYY').format('MMMM YYYY');
monthDict[month] = monthDict[month] || [];
monthDict[month].push(record);
});
for (record in monthDict) {
var month = record;
for (item in monthDict[record]) {
monthDict[record][item]['month'] = month;
}
};
$scope.monthlist = monthDict;
的问题是,我认为,要实现什么,我需要我不得不从每月阵列中提取的独特的赛车和车手的名单,并将它推回
这就是我想我可能需要的结构:
November: {
Trips: [
Object 1 {}
Object 2 {}
]
Cars: [
369 [
Object 1 {}
]
210 [
Object 1 {}
]
]
Drivers: [
Jenny [
Object 1 {}
Object 2 {}
],
Mango [
Object 1 {}
Object 2 {}
]
]
}
因此,基本上,为每个独特的月份创建一个对象,然后在每个月份为每个独特的汽车和每个独特的驱动程序创建一个数组。
如何到达那里的任何提示?我担心现在对我来说有点过于先进。