2017-11-23 4 views
0
export class HomePage { 
    items = [ 
    { 
     title: 'Courgette daikon', 
     content: 'Parsley amaranth tigernut silver beet maize fennel spinach. Ricebean black-eyed pea maize scallion green bean spinach cabbage jícama bell pepper carrot onion corn plantain garbanzo. Sierra leone bologi komatsuna celery peanut swiss chard silver beet squash dandelion maize chicory burdock tatsoi dulse radish wakame beetroot.', 
     icon: 'calendar', 
     time: {subtitle: '4/16/2013', title: '21:30'} 
    }, 
    { 
     title: 'Courgette daikon', 
     content: 'Parsley amaranth tigernut silver beet maize fennel spinach. Ricebean black-eyed pea maize scallion green bean spinach cabbage jícama bell pepper carrot onion corn plantain garbanzo. Sierra leone bologi komatsuna celery peanut swiss chard silver beet squash dandelion maize chicory burdock tatsoi dulse radish wakame beetroot.', 
     icon: 'calendar', 
     time: {subtitle: 'January', title: '29'} 
    }, 
    { 
     title: 'Courgette daikon', 
     content: 'Parsley amaranth tigernut silver beet maize fennel spinach. Ricebean black-eyed pea maize scallion green bean spinach cabbage jícama bell pepper carrot onion corn plantain garbanzo. Sierra leone bologi komatsuna celery peanut swiss chard silver beet squash dandelion maize chicory burdock tatsoi dulse radish wakame beetroot.', 
     icon: 'calendar', 
     time: {title: 'Short Text'} 
    } 
    ] 
    constructor(public navCtrl: NavController) { 

    } 

} 

InstedにJSONをインポートする方法を、私はイオン3でそれを読み取ろうとイオンタイムラインプロジェクト手動で入力されたJSONの

{"items":[{"agendaid":"1","title":"Avreise Medina","content":"Avreise til Medina er klokken 18:30, det er oppm\u00f8te p\u00e5 flyplassen 3 timer f\u00f8r avreise. Alle m\u00e5 selv komme tidsnok til \u00e5 f\u00e5 sitte sammen andre i familien. Det er kun lov til \u00e5 ha med seg 30 kg baggasje og 7 kg h\u00e5ndbaggasje","icon":"plane","TimeTitle":"21.12.2017","TimeSubtitle":"18:30","ExecuteTime":"2017-12-21 18:30:00"},{"agendaid":"2","title":"test","content":"test","icon":"test","TimeTitle":"test","TimeSubtitle":"test","ExecuteTime":"2017-11-22 17:26:23"}]}

イムあるJSONファイルからこれをインポートしたいですこのコード

url: string = 'http://backend.mishkaat.no/app/agenda.php'; 
     items: any = []; 

     constructor(public navCtrl: NavController, public navParams: NavParams,private http: Http) {} 

     ionViewDidEnter() { 
      this.http.get(this.url) 
      .map(res => res.json()) 
      .subscribe(data => { 
       // we've got back the raw data, now generate the core schedule data 
       // and save the data for later reference 
       this.items = data; 
      }); 
     } 

しかし、このエラーを取得:

Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed 
     at DefaultIterableDiffer.diff (http://localhost:8100/build/vendor.js:7695:19) 
     at NgForOf.ngDoCheck (http://localhost:8100/build/vendor.js:43776:57) 
     at checkAndUpdateDirectiveInline (http://localhost:8100/build/vendor.js:12451:19) 
     at checkAndUpdateNodeInline (http://localhost:8100/build/vendor.js:13951:20) 
     at checkAndUpdateNode (http://localhost:8100/build/vendor.js:13894:16) 
     at debugCheckAndUpdateNode (http://localhost:8100/build/vendor.js:14766:76) 
     at debugCheckDirectivesFn (http://localhost:8100/build/vendor.js:14707:13) 
     at Object.eval [as updateDirectives] (ng:///AppModule/AgendaPage.ngfactory.js:99:5) 
     at Object.debugUpdateDirectives [as updateDirectives] (http://localhost:8100/build/vendor.js:14692:21) 
     at checkAndUpdateView (http://localhost:8100/build/vendor.js:13861:14) 

htmlファイル

<timeline endIcon="call"> 
     <timeline-item *ngFor="let item of items"> 
      <timeline-time [time]="item.time"></timeline-time> 
      <ion-icon [name]="item.icon"></ion-icon> 
      <ion-card> 
      <ion-card-header> 
       {{item.title}} 
      </ion-card-header> 
      <ion-card-content> 
       {{item.content}} 
      </ion-card-content> 
      </ion-card> 
     </timeline-item> 
    </timeline> 

すべてのヘルプでそれを表示しますか?

+0

このコード 'this.itemsの=のdata.itemsを確認してください;' –

+0

ありがとうございました!それはそれを解決しました! –

+0

新しい質問が到着しました。 –

答えて

0

私は今問題の元のjsonファイルを持っていますが、なぜこのスクリプトで入れ子になったjsonを読むことができませんか?

@Component({ 
    selector:'timeline-time', 
    template: '<span>{{time.subtitle}}</span> <span>{{time.title}}</span>' 
}) 
export class TimelineTimeComponent{ 
    @Input('time') time = {}; 
    constructor(){ 

    } 
} 
+0

あなたは新しいページであなたの質問を答えなければならない。 –