【问题标题】:How to display Data from Json Mapper in Angular 5?如何在 Angular 5 中显示来自 Json Mapper 的数据?
【发布时间】:2018-06-12 22:29:23
【问题描述】:

我是使用 TypeScript 的 Angular5 的初学者,我试图找到如何从我的 JSON 中显示我的数据.. 事实上,我有一个用 Java 创建的 API。 在我的 Angular 中,我创建了一个这样的 JSON 映射器:

我的 java 中的 Json 如下所示:

 [
        {
            "type": "SERVICE",
            "nom": "aide-services",
            "equipes": [
                {
                    "nom": "IKKI"
                }
            ],
            "serveurs": [
                {
                    "id": 2,
                    "nom": "vtcint2",
                    "ip": "10.10.25.45",
                    "indicateurs": {
                        "BUILDDATE": "2018-01-03T06:02:05Z",
                        "STATUS": "OK",
                        "VERSION": "2.2.0-SNAPSHOT"
                    }
                }
            ]

目前,我只能显示来自 Applications 的 type 和 nom,如下所示: {{app.type}} {{app.nom} 但是当我想显示例如来自服务器的数据时,我不能 {{app.serveurs}} 我的 HTML 显示中有 [Object object] 请问,我该如何解决这个问题? 提前致谢

【问题讨论】:

    标签: json typescript angular5


    【解决方案1】:
    <code>
    
    interface Applications {
      type : string;
      nom : string;
      equipes: Equipe[];
      serveurs: Serveur[];
    }
    
    interface Equipe {
      nom : string;
    }
    
    interface Serveur {
      id: number;
      nom: string;
      ip: string;
      indicateurs: Indicateurs;
    }
    
    interface Indicateurs {
      BUILDDATE: Date;
      STATUS: string;
      VERSION: string;
    }
    
    </code>
    

    【讨论】:

      【解决方案2】:

      我解决了我的问题。 我只需要像这样迭代:

      <div *ngFor="let s of apps">{{s.serveurs.VERSION
      

      这只是一个例子,为可能遇到像我一样的问题的人说明解决方案。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-15
        • 2018-08-30
        • 1970-01-01
        • 1970-01-01
        • 2022-01-08
        相关资源
        最近更新 更多