简体   繁体   English

显示数组中的json数据

[英]display json data from array

I'm trying to display some json data I got from a get request. 我正在尝试显示从get请求获得的一些json数据。 So far I've been able to display other arrays with no problem, but I'm having trouble displaying this particular array for some reason, and I'm not getting any errors. 到目前为止,我已经能够毫无问题地显示其他数组,但是由于某种原因,我无法显示该特定数组,并且没有出现任何错误。

the one that won't display correctly is the showtimes array. 不能正确显示的是showtimes数组。

在此处输入图片说明

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

You are missing {{}} expression 您缺少{{}}表达式

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

EDIT 编辑

Change it to some other variable name, since you are already using shows, 将其更改为其他变量名称,因为您已经在使用节目,

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

As it looks from your snapshot, the array of objects is stored in variable showtimes , if that is the case, try the below code: 从快照看,对象数组存储在变量showtimes ,如果是这种情况,请尝试以下代码:

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

A nested ngFor loop solved the problem.. 嵌套的ngFor循环解决了这个问题。

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

works perfectly, thanks for the help 工作完美,谢谢您的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM