如何在打字稿/离子2中按星期分组时间戳?
问题描述:
我已经把下面的json放到了一个名为logs的数组中,并且希望使用创建的时间戳对每周进行分组。如何在打字稿/离子2中按星期分组时间戳?
{
created : "2017-07-15 09:49:37"
entry : "this is a log entry"
}
created : "2017-07-13 09:49:37"
entry : "this is a log entry"
}
{
created : "2016-05-13 11:00:21"
entry : "this is another log entry"
}
和离子2 html。
<div *ngFor="let log of logs">
<ion-list-header>
{{log.created}}
</ion-list-header>
<ion-item>
{{log.entry}}
</ion-item>
</div>
编辑
好,我现在在做PHP每周分组返回下面的JSON,
"payload": {
"logs": {
"19": [
"[{\"entry\":"this is an entry",\"created\":\"2017-05-12 09:51:18\"}]"
],
"28": [
"[{\"entry\":"this is an entry",\"created\":\"2017-07-15 09:50:50\"}]",
"[{\"entry\":"this is an entry",\"created\":\"2017-07-15 09:51:18\"}]"
]
}
我收到像这样,
private weeks: any[];
this.api.getLogs().subscribe(
data => {
// Success
this.weeks = data.payload.logs;
},
err => {
//Err
}
);
,我试图在Ionic 2中使用它,
<div *ngFor="let week of weeks">
<div *ngFor="let log of week">
{{log.created}}
</div>
</div>
但给了我下面的错误,
Runtime Error
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
任何帮助表示赞赏。
感谢
答
您声明weeks
为任何(private weeks: any[];
)数组,但你用JSON(data.payload.logs
是JSON)设置它,这样看来,你至少有一个类型的错误在这里。
请问您能告诉我们到目前为止您尝试了些什么? – sebaferreras
嗨,我已编辑帖子以显示我目前的情况。我已经在PHP方面分了几周,但我有问题让json进入列表。 – Dunny