简体   繁体   English

如何构造可观察到的.map()来更改从http.get()返回的数据

[英]How to construct the .map() observable to change data returned from http.get()

I'm trying to map the results returned from a fake endpoint that contains an array of user objects with properties like id. 我正在尝试映射从伪造的端点返回的结果,该伪造的端点包含具有ID等属性的用户对象数组。 But I can't figure out what to put into the map operator to make it work, for example, I want to add 10 to all the IDs. 但是我不知道要在地图运算符中添加什么才能使其正常工作,例如,我想在所有ID中添加10。 Here's my service's code: 这是我的服务代码:

getUsers(): Observable<IUsers[]> {
    return this._http.get<IUsers[]>('https://jsonplaceholder.typicode.com/users')
      .map((users: IUsers[]) => users.find(x => (x.id + 10)))
      .do(data => console.log('All: ' + JSON.stringify(data)))
      .catch(this.handleError);
}

inside .find() , it returns 'number' not assignable to type 'boolean' . .find()内部,它返回'number' not assignable to type 'boolean' How should I construct this the arrow function in my .map() ? 我应该如何在我的.map()构造箭头功能?

I think you want to replace your find by a map . 我认为您想用map代替您的find Find returns the value for which your evaluation is true . Find返回您的评估为true的值。 (x.id + 10) isn't. (x.id + 10)不是。 That is why you get that error. 这就是为什么您会收到该错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM