.map 不是 Angular 2 中的函数,导入地图运算符不起作用



这是我的代码,我不知道为什么这说.map不是一个函数。这是一种通用方法。

  public findTeamRoles(id: any, userId: any): Observable<any> {
let _method: string = "GET";
let _url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/Programs/:id/findTeamRoles";
let _routeParams: any = {
  id: id
};
let _postBody: any = {};
let _urlParams: any = {};
if (userId) _urlParams.userId = userId;
let result = this.request(_method, _url, _routeParams, _urlParams, _postBody);
return result.map((instances: Array<Program>) =>
    instances.map((instance: Program) => new Program(instance))
);
}

我收到此错误:

 core.es5.js:1084 ERROR TypeError: instances.map is not a function

该错误只有一种可能性。Map 是 Array 的原型函数,因此instances nullundefined

我在打字稿文件中收到此错误,我正在从服务中提取一些数据。而且我知道mapArray的原型函数.所以我只是在查看代码,我发现我的函数中缺少一个await关键字。这是一个小错误。

以前

public async getAddressesBySupplierId(supplierId: string): Promise<IAddressData[]> {
        const addresses: IAddressData[] = this.spFilter.getItems({
            title: config.listNames.adress
        });
        const addressWithType = addresses.map(async (address) => {
        const addressType = await this.getAddressTypeById(address.AdressartIdId);
        return await this.mapAddressType(address, addressType);
    });
        return Promise.all(addressWithType);
    }

public async getAddressesBySupplierId(supplierId: string): Promise<IAddressData[]> {
        const addresses: IAddressData[] = await this.spFilter.getItems({
            title: config.listNames.adress
        });
        const addressWithType = addresses.map(async (address) => {
        const addressType = await this.getAddressTypeById(address.AdressartIdId);
        return await this.mapAddressType(address, addressType);
    });
        return Promise.all(addressWithType);
    }

如您所见,在第一个代码块上,我在第二行(this.spFilter.getItems调用之前(缺少async关键字。

最新更新