1
の適用明確な:角度2 Rxjs:私は、これらのオブジェクトのobeservablesを持つオブジェクト
{
id : "f3055770-6e66-4936-8e9a-732b53121549"
message:"Empty Notification for test ......"
navigationLink:"/fusion/home"
seen:false
sendedOn:"2016-12-02T15:19:44.856Z"
userId :null
}
私は(IDに基づいて)重複したオブジェクトを受け取り、私はそれを
notify(userID: string) {
return Observable.interval(5000)
.map(() => this.baseUrl + '/notification/GetUnseen?userId=' + userID)
.switchMap(url => {
return Observable.from(this.datatService.get(url));
})
.flatMap(response => Observable.from(response.json().slice()))
}
を達成するために、このメソッドを使用しないしたいと思います
は、私が代わりに任意のヘルプ四のオブジェクトを1つだけ持って、最後の作業として、明確な(X => x.id)を追加すると?
UPDATE:メソッドは、通知を得るために、すべての5秒を実行するよう
は私がdistictこの方法を使用して、私のコンポーネントののOnInit()のライフサイクルでは、このメソッドを呼び出します。
notify(userID: string) {
return Observable.interval(5000)
.map(() => this.baseUrl + '/notification/GetUnseen?userId=' + userID)
.switchMap(url => {
return Observable.from(this.datatService.get(url));
})
.flatMap(response => Observable.from(response.json().slice()))
.distinct(x => x.id);
}
UPDATE 2
Serveur生応答:
"[{"userId":null,"sendedOn":"2016-12-02T15:19:44.856Z","message":"Empty Notification for test ......","navigationLink":"/fusion/home","seen":false,"id":"f3055770-6e66-4936-8e9a-732b53121549"},{"userId":null,"sendedOn":"2016-12-02T15:19:45.146Z","message":"Empty Notification for test ......","navigationLink":"/fusion/home","seen":false,"id":"ce172122-11d9-4054-a3e4-594c8c910a7d"},{"userId":null,"sendedOn":"2016-12-02T15:19:45.146Z","message":"Empty Notification for test ......","navigationLink":"/fusion/home","seen":false,"id":"66e32c45-f544-4ce6-901c-e5ac64904954"},{"userId":null,"sendedOn":"2016-12-02T15:19:45.147Z","message":"Empty Notification for test ......","navigationLink":"/fusion/home","seen":false,"id":"4c2322cb-526c-490e-8a86-f1e9ced1c34f"}]"
あなたはコンテキストをお願いできます:1)どのようにこのメソッドを呼び出していますか? 2) 'distinct'演算子はどこに追加しますか? – Meir
これらの4つのオブジェクトに同じ「id」がないことは確かですか? IDが同じ – martin
更新、@martinええ午前SHURE? –