2017-02-25 8 views
0

私はdatatables(datatables.net)を使用していますが、オブジェクトを取得するためにAngularFire2を使用してFirebaseからデータテーブルのデータを取得したいとします。AngularFire firebaseListObservableオブジェクトをプレーンオブジェクトに変換する

しかし、これはFirebaseListObservableオブジェクトを取得します。以前は普通のオブジェクトを使用していたデータテーブルでこれを使用する方法がわかりません。

このようにFirebaseListObservableをプレーンオブジェクトに変換する方法はありますか?

component.html

<sa-datatable 
      [options]="{ 
       data: rfis, 
       columns: [ 
       {data: 'rfiNo'}, 
       {data: 'title'}, 
       {data: 'status'} 
       ] 
      }" 
      filter="true" tableClass="table table-condenced table-striped table-bordered" 
      paginationLength="true" tableClass="table table-striped table-bordered table-hover" 
      width="100%"> 
      <thead> 
       <tr> 
       <th data-class="expand"><i 
        class="fa fa-fw fa-user text-muted hidden-md hidden-sm hidden-xs"></i> 
        Lot # 
       </th> 
       <th> 
        Lot Name 1 
       </th> 
       <th> 
        Lot Name 2 
       </th> 
       </tr> 
      </thead> 
      </sa-datatable> 

component.ts

import { Component, OnInit } from '@angular/core'; 
import {FadeInTop} from "../shared/animations/fade-in-top.decorator"; 
import {RfisData} from "../providers/rfis-data"; 

@FadeInTop() 
@Component({ 
    selector: 'app-lots', 
    templateUrl: './lots.component.html', 
    providers: [RfisData] 
}) 
export class LotsComponent implements OnInit { 
    rfis: any; 
    data: any; 

    constructor(
    public rfisService: RfisData 
) {} 

    ngOnInit() { 
    this.rfis = this.rfisService.getRfis(); 
    this.data = this.rfisService.getData(); 
    } 
} 

provider.ts

import { Injectable } from "@angular/core"; 
import { AngularFire, FirebaseListObservable } from 'angularfire2'; 

@Injectable() 
export class RfisData { 
    rfis: FirebaseListObservable<any>; 
    data: any; 

    constructor(
    af: AngularFire 
) { 

// this just to compare object types 
    this.data =[ 
     { 
      "rfiNo": "Frist RFI", 
      "status": "open", 
      "title": "Its a fucking RFI dude" 
     } 
     ];  

    this.rfis = af.database.list('/rfis'); 

    } 

    getRfis(){ 
    console.log(this.rfis); 
    return this.rfis; 
    } 

// this just to compare object types 
    getData(){ 
    console.log(this.data); 
    return this.data; 
    } 

} 

コンソールログからの結果は、オブジェクトのための2つの結果を示し、一方はありますfirebaseListObservableオブジェクト、もう一方はプレーンな[Object]です。

ありがとうございます。

答えて

1

これが私の仕事:

af.database.object('/some/ref/to/object') 
    .map(val => Object.assign(new MyPlainObject(), val); 
+0

おかげでロビン。簡単な作業ソリューション:) – npasco

関連する問題