如何使用Angular过滤器按时间戳对数据进行分组
How can I group data with an Angular filter by timestamp?
我的MVC返回此JSON
[
{
"$id":"1",
"Tags":
[
{"$id":"2","Values":
[
{"$id":"3","Tag":{"$ref":"2"},"ID":4,"TagID":1,"Value1":5.00,"TimeStamp":"2015-10-26T15:23:50","Quality":1,"Tags_ID":1},
{"$id":"4","Tag":{"$ref":"2"},"ID":7,"TagID":1,"Value1":4.00,"TimeStamp":"2015-10-26T15:25:50","Quality":2,"Tags_ID":1}
],"Reports":[{"$ref":"1"}],"ID":1,"Name":"0101WT370/WT.VALUE","Type":null,"Archive":null,"Server":null,"Created":null,"Edited":null},
{"$id":"5","Values":[],"Reports":[{"$ref":"1"}],"ID":2,"Name":"0101WT371/WT.VALUE","Type":null,"Archive":null,"Server":null,"Created":null,"Edited":null},
{"$id":"6","Values":[],"Reports":[{"$ref":"1"}],"ID":3,"Name":"0101WT395/WT.VALUE","Type":null,"Archive":null,"Server":null,"Created":null,"Edited":null},
{"$id":"7","Values":[],"Reports":[{"$ref":"1"}],"ID":4,"Name":"0101WT396/WT.VALUE","Type":null,"Archive":null,"Server":null,"Created":null,"Edited":null}
],
"ID":3,"Name":"A"
},
{
"$id":"8",
"Tags":[],"ID":4,"Name":"B"
}
]
我希望winth Angular按时间戳对值进行分组——每小时、每天或每月
我每天都想要这个结果示例:
标记|时间戳|值|
Tag1 | 2015年10月26日| 4.5=(9/2)=值1+值2/计数
你能给我什么建议吗?
编辑:
我发现这给了我一些类似的开始方式:)
尝试以下代码:
JAVASCRIPT
function sortTimeStamp(obj) {
for(i=0; i<obj.length;i++) {
for(z=0; z<obj[i].Tags.length;z++) {
for(y=0; y<obj[i].Tags[z].Values.length;y++) {
obj[i].Tags[z].Values.sort(function (a, b) {
return new Date(b.TimeStamp).getTime() - new Date(a.TimeStamp).getTime();
});
}
}
}
return obj;
}
var myObj = [
{
"$id": "1",
"Tags": [
{
"$id": "2",
"Values": [
{
"$id": "3",
"Tag": {
"$ref": "2"
},
"ID": 4,
"TagID": 1,
"Value1": 5,
"TimeStamp": "2015-10-26T15:23:50",
"Quality": 1,
"Tags_ID": 1
},
{
"$id": "4",
"Tag": {
"$ref": "2"
},
"ID": 7,
"TagID": 1,
"Value1": 4,
"TimeStamp": "2015-10-26T15:25:50",
"Quality": 2,
"Tags_ID": 1
}
],
"Reports": [
{
"$ref": "1"
}
],
"ID": 1,
"Name": "0101WT370/WT.VALUE",
"Type": null,
"Archive": null,
"Server": null,
"Created": null,
"Edited": null
},
{
"$id": "5",
"Values": [],
"Reports": [
{
"$ref": "1"
}
],
"ID": 2,
"Name": "0101WT371/WT.VALUE",
"Type": null,
"Archive": null,
"Server": null,
"Created": null,
"Edited": null
},
{
"$id": "6",
"Values": [],
"Reports": [
{
"$ref": "1"
}
],
"ID": 3,
"Name": "0101WT395/WT.VALUE",
"Type": null,
"Archive": null,
"Server": null,
"Created": null,
"Edited": null
},
{
"$id": "7",
"Values": [],
"Reports": [
{
"$ref": "1"
}
],
"ID": 4,
"Name": "0101WT396/WT.VALUE",
"Type": null,
"Archive": null,
"Server": null,
"Created": null,
"Edited": null
}
],
"ID": 3,
"Name": "A"
},
{
"$id": "8",
"Tags": [],
"ID": 4,
"Name": "B"
}
];
myObj = sortTimeStamp(myObj);
console.log(myObj);
https://jsfiddle.net/3y7wfqwq/
相关文章:
- 如何每10.6秒从时间戳增加+1
- 使用AngularJS从时间戳中获取工作日
- 将时间戳转换为java中的ISO860,
- Javascript Unix时间戳转换
- JavaScript JSON关联对象键和值都作为日期时间戳
- 时间戳与mongoskin如何
- 用时间戳获取两个不同日期之间的时间差
- JavaScript到PHP的时间戳失败,增加了大约一个半月的时间
- 转换unix时间戳转换
- 带有unix时间戳的d3.js平分线
- 折线图:对齐多个数据集的x轴(时间戳)
- 将多个csv文件中的时间戳数据添加到highchart中
- 生成时间戳日期|Javascript范围内的空数据
- 如何将人类可读的数据转换为时间戳(使用JS)
- 基于时间戳组织JSON数据.帮助会很好
- 从数据表中的日期字段中删除时间戳
- 如何使用Angular过滤器按时间戳对数据进行分组
- 为fooTable获取正确的数据值(ticks或unix时间戳)
- 格式化日期时间mysql数据类型的时间戳
- 如何在javascript中对数据时间戳进行排序