2017-09-13 67 views
0

我試圖顯示一些json數據,我從get請求中獲取。到目前爲止,我已經能夠顯示其他數組沒有問題,但由於某種原因,我無法顯示這個特定的數組,並且我沒有收到任何錯誤。從數組顯示json數據

不能正確顯示的是放映時間數組。

enter image description here

<div *ngIf="show"> 
<div *ngFor="let shows of show"class="showtime"> 
<div class="panel panel-default"> 
    <div class="panel-heading"> 
     <h3 class="panel-title">{{shows.title}}</h3> 
    </div> 
    <div class="panel-body" > 
     <div class="row"> 
      <div class="col-md-7 col-sm-5 col-xs-12 "> 

       <img class="thumbnail movie_pic" src="http://developer.tmsimg.com/{{shows.preferredImage.uri}}?api_key={{api}}"><br> 

      </div> 
      <div class="col-md-5 col-sm-7 col-xs-12"> 
       <ul class="list-group"> 
        <li class="list-group-item">Genres: {{shows.genres}}</li> 
        <li class="list-group-rel">Release Date: {{shows.releaseDate}}</li> 
        <li class="list-group-rel">{{shows.longDescription}}</li> 
        <li *ngFor="let shows of show.showtimes" class="list-group-rel">shows.theatre.name</li> 
       </ul> 

      </div> 
     </div> 

    </div> 
    </div> 
    </div> 
    </div> 
+1

旁註:你可以使用'ngIf'和'ngFor'在相同的代碼。不需要額外的'div'。 – mok

回答

0

嵌套的循環ngFor解決了這個問題..

<div *ngFor="let shows of show"> 
    <div *ngFor="let detail of shows.showtimes"> 
    <p>{{detail.theatre.name}}</p> 
    </div>    
</div> 

作品完美,感謝您的幫助

4

你缺少{{}}表達

<li *ngFor="let shows of show.showtimes" class="list-group-rel">{{shows.theatre.name}}</li> 

編輯

它更改爲其他變量名,因爲你已經在使用顯示,

<li *ngFor="let showdetail of show.showtimes" class="list-group-rel">{{showdetail.theatre.name}}</li> 
+0

噢,我忘了包括,但是這並沒有解決問題 – Jason

+0

@Jason檢查更新的答案 – Sajeetharan

+0

這是一個好主意,但由於某種原因,它仍然無法正常工作 – Jason

1

當它從你的快照看起來,對象的數組存儲在變量showtimes,如果是這樣的話,試試下面的代碼:

<li *ngFor="let detail of showtimes" class="list-group-rel"> 
    {{detail.theatre.name}} 
</li>