【发布时间】:2017-12-20 17:59:24
【问题描述】:
我已将以下 json 放入一个名为 logs 的数组中,并希望使用创建的时间戳对每周进行分组。
{
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"
}
还有 ionic 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.
任何帮助表示赞赏。
谢谢
【问题讨论】:
-
您能告诉我们到目前为止您尝试了什么吗?
-
嗨,我已经编辑了帖子以显示我目前的情况。我在 php 方面按周分组,但在将 json 放入列表时遇到问题。
标签: arrays typescript ionic2 timestamp filtering