【发布时间】:2016-10-18 05:53:42
【问题描述】:
我有一个像这样调用 API 的服务:
return this._http
.post(appSettings.apiUrl + 'SomeController/SomeAction', params, {withCredentials: true, headers: this.headers})
.timeoutWith(appSettings.maxTimeHttpCalls, Observable.defer(() => Observable.throw(this._feedbackService.timeout())))
.map((response: Response) => response.json().data);
现在我想使用rxjs/add/operator/filter 对该调用实现过滤功能,但我无法使其正常工作。
这是我采取的方法:
return this._http
.post(appSettings.apiUrl + 'SomeController/SomeAction', params, {withCredentials: true, headers: this.headers})
.timeoutWith(appSettings.maxTimeHttpCalls, Observable.defer(() => Observable.throw(this._feedbackService.timeout())))
.filter(response => response.json().data.Type === 5)
.map((response: Response) => response.json().data);
但无论我过滤什么,只要过滤器在那里,ngFor 循环就不会产生任何结果。如果我删除它,一切都会按预期进行。
我应该在map 之前还是之后添加过滤器?
我可以像这样过滤响应 JSON,还是需要使用其他语法?
JSON 示例
以下是响应 JSON 的示例:
data: [
{
"Type": 5,
"Description": "Testing",
"ID": "001525"
}
]
【问题讨论】:
-
最可能的解释是json的data字段的Type字段不等于5。什么是json?
标签: angular rxjs observable