RxJS与属性中的对象数组不同

时间:2019-11-20 09:15:59

标签: rxjs

我有一个可观察到的东西,返回的内容如下:

"@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"
        }
    ]
}

你能帮我吗?

1 个答案:

答案 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只会收集所有结果。

实时演示:https://stackblitz.com/edit/rxjs-is1zp4