如何用*ngFor显示多维数组?

How to display multidimensional array with *ngFor?

我是 js,ts,ionic 新手

我在 home.ts:

中得到了这个名为 'stores' 的数组
0: {name: "wwwe", floor: 1}
1: {name: "weeqe", floor: -3}
2: {name: "weewqe", floor: -2}
3: {name: "qweqweqwe", floor: -2}

我也需要通过 *ngFor 来展示它。我在 home.html:

中有这个
<ion-card *ngFor="let store of stores">
<ion-card-header >
{{store.name}}
</ion-card-header>
</ion-card>

但这是显示空页!

求助

我也试过这个:

<ion-card *ngFor="let store of stores; let i=index">
<ion-card-header >
{{store[i].name}}
</ion-card-header>
</ion-card>

不工作。

我读到必须将对象更改为数组,但我不明白在我的情况下该怎么做。我需要将所有数组值放在一个地方。

home.ts:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {


constructor(public navCtrl: NavController, public http: Http) {
    var stores: Store[] = []
    var json;
    this.http.get('http/link/to/json').map(res => res.json()).subscribe(data => {
            json = data.data;
            for (var i of json.stores){
                stores.push({ 'name': i.name, 'floor': i.floor[0]  });
            }

        });

    console.log(stores);

  }


}

这是演出 console.log(商店):

https://i.stack.imgur.com/TGsys.png

你必须在构造函数外声明stores变量

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {

// This way so you can reference it in the ngFor
stores: Store[] = [] 

constructor(public navCtrl: NavController, public http: Http) {
    var json;
    this.http.get('http/link/to/json').map(res => res.json()).subscribe(data => {
            json = data.data;
            for (var i of json.stores){
                this.stores.push({ 'name': i.name, 'floor': i.floor[0]  });
            }

        });

    console.log(this.stores);

  }


}