我有一个可观察到的东西,返回的内容如下:
"@odata.context": "here is the context URL",
"value": [
{
"Id": 1,
"Value": "A"
},
{
"Id": 2,
"Value": "B"
},
{
"Id": 3,
"Value": "C"
},
{
"Id": 4,
"Value": "A"
}
]
}
我想使用RxJS进入“值”属性,并在其上使用distinct,以将响应限制为如下所示:
"@odata.context": "here is the context URL",
"value": [
{
"Id": 1,
"Value": "A"
},
{
"Id": 2,
"Value": "B"
},
{
"Id": 3,
"Value": "C"
}
]
}
你能帮我吗?
答案 0 :(得分:1)
这在很大程度上取决于您要使用此RxJS链的精确程度,但是我希望这可以为您指明正确的方向:
use Symfony\Component\DependencyInjection\Reference;
...
$comrade->addMethodCall('setCache', new Reference($config['cache_service']));
...
const source = of(data)
.pipe(
mergeMap(d => d.value),
distinct(v => v.Value),
toArray(),
)
.subscribe(console.log);
会将值数组重申为单独的发射,其中mergeMap
将忽略重复的distinct
。然后Value
只会收集所有结果。