2017-07-15 6 views
0

私は、以下のjsonをlogsという配列に入れました。作成したタイムスタンプを使ってその週ごとにグループ化したいと思います。typescript/ionic 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" 
} 

およびイオン性2html。

<div *ngFor="let log of logs"> 
     <ion-list-header> 
      {{log.created}} 
     </ion-list-header> 
    <ion-item> 
     {{log.entry}} 
    </ion-item> 
</div> 

私は今、私は、

private weeks: any[]; 

this.api.getLogs().subscribe(
     data => { 
     // Success 
     this.weeks = data.payload.logs; 
     }, 
     err => { 
     //Err 
     } 
    ); 
のようにそれを受け取り、

"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\"}]" 
    ] 
} 

をJSONの下に返すPHPで毎週のグループ化を行ってきた[OK]をEDIT

と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. 

すべてのヘルプは大歓迎します。

おかげ

+0

あなたはこれまでに何を試しましたか教えてください。 – sebaferreras

+0

こんにちは、現在の状況を示すために投稿を編集しました。私はPHP側で数週間でグループ化しましたが、私はリストにjsonを得ることに問題があります。 – Dunny

答えて

0

あなたはいずれかの配列(private weeks: any[];)としてweeksを宣言していますが(data.payload.logsがJSONである)JSONでそれを設定し、あなたがここに少なくとも型エラーを持っているようです。

関連する問題