处理ngx-datatable中的服务器响应数据

时间:2018-02-28 06:36:43

标签: angular observable ngx-datatable

我正在尝试从服务器获取数据并将其传递给datatable但无法处理它。需要帮忙。我无法很好地理解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;
    }

}

`

1 个答案:

答案 0 :(得分:1)

我认为你只宣布一个Observable。你可以试试getResults()。subcribe(data =&gt; doSomethings())