0
我正在使用datatables(datatables.net),並且想從Firebase中使用AngularFire2獲取對象的數據。將AngularFire的firebaseListObservable對象轉換爲純文本對象
但是,這會得到一個FirebaseListObservable對象,我不知道如何在datatables中使用它,我以前使用過普通對象。
有沒有辦法將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;
}
}
從控制檯日誌結果表明將兩個結果的目的,一個是firebaseListObservable對象,另一個是普通的[Object]。
謝謝。
感謝羅賓。簡單的工作方案:) – npasco