首先:Plunkr Example is here <-- NOW: WORKING EXAMPLE (edited)
这是数据:
[
{
"label": "One",
"value": 1
},
{
"label": "Two",
"value": 2
},
{
"label": "Three",
"value": 3
}
]
这是过滤器:
http.get('./data.json')
.map(data => data.json())
.filter (
(x,index) => return x[index].value === 2
)
.subscribe(data => this.d = data);
我想得到结果:
{
"label": "Two",
"value": 2
}
也许我停电了,哪里出错了?
答案 0 :(得分:1)
在这种情况下,您可以使用.concatMap
http.get('./data.json')
.map(res => res.json())
.concatMap(res => res)
.filter(x => x.value === 2)
.subscribe(data => {
this.d = data;
});