Javascript 如何转换可观测响应以返回现有对象而不是新对象?

Javascript 如何转换可观测响应以返回现有对象而不是新对象?,javascript,angular,typescript,rxjs,observable,Javascript,Angular,Typescript,Rxjs,Observable,这就是我现在所拥有的: cachedEntities: Map<string, CareerPreferenceMyCareer> = new Map<string, CareerPreferenceMyCareer>(); getByEmployeeId(employeeId: string): Observable<CareerPreferenceMyCareer> { return this.http.get<CareerPreferen

这就是我现在所拥有的:

cachedEntities: Map<string, CareerPreferenceMyCareer> = new Map<string, CareerPreferenceMyCareer>();

getByEmployeeId(employeeId: string): Observable<CareerPreferenceMyCareer> {
    return this.http.get<CareerPreferenceMyCareer>(`${this.startupService.settings.coreUrl}/${this.serviceEndpoint}/ByEmployee/${employeeId}`).pipe(
      map(res => {
        if (res)
          this.cachedEntities.set(employeeId, res); //I want to get exatly this object but map operator creates a new object
        return this.cachedEntities.get(employeeId);
      })
    );
  }
cachedEntities:Map=newmap();
getByEmployeeId(employeeId:string):可观察{
返回this.http.get(`${this.startupService.settings.coreUrl}/${this.serviceEndpoint}/ByEmployee/${employeeId}`).pipe(
地图(res=>{
如果(res)
this.cachedenties.set(employeeId,res);//我想获取这个对象,但map操作符创建了一个新对象
返回此.cachedenties.get(employeeId);
})
);
}
我知道新对象是因为
map
pipe操作符而创建的,但是是否可以获取现有对象而不是新对象?也许和另一个接线员一起


我希望能很好地解释我的问题。提前感谢,如果我写的任何错误有误,请纠正我。

否。地图操作员不要创建新对象。返回完全相同的对象。您的功能是创建一个新对象。请参见示例:

rxjs
map
,以及设置和获取
map
条目都不会创建新对象。问题一定在别的地方。