我正在尝试从服务器获取数据并将其传递给数据表但无法处理。需要帮忙。我不能很好地理解 Observable。`
@Injectable()
export class MockServerResultsService {
companyData: ReportsTable[];
constructor(private http: Http, private httpClient: HttpClient) { }
public getResults(page: Page): Observable<PagedData<ReportsTable>> {
return Observable.of(this.httpClient.get<ReportsTable[]>(API_URL + 'getVerifidEmailsReport', {
observe: 'body',
responseType: 'json'
}).map(
(data) => {
this.companyData = data;
}
)).map(
data => this.getPagedData(page)
);
}
private getPagedData(page: Page): PagedData<ReportsTable> {
let pagedData = new PagedData<ReportsTable>();
page.totalElements = this.companyData.length;
let end = Math.min((start + page.size), page.totalElements);
for (let i = start; i < end; i++) {
let jsonObj = this.companyData[i];
let employee = new ReportsTable(
jsonObj.file_name,
jsonObj.file_size,
);
pagedData.data.push(employee);
}
pagedData.page = page;
return pagedData;
}
}
`