Rxjs正在获得AjaxObservable而不是ajax响应
我有下一个可观察的对象,我试图过滤以获取网络中的用户,但是.mapTo(phone=>verifyPhoneInNetwork(phone,country))返回AjaxObservable,而不是ajax响应Rxjs正在获得AjaxObservable而不是ajax响应,rxjs,observable,rxjs5,rxjs-dom,Rxjs,Observable,Rxjs5,Rxjs Dom,我有下一个可观察的对象,我试图过滤以获取网络中的用户,但是.mapTo(phone=>verifyPhoneInNetwork(phone,country))返回AjaxObservable,而不是ajax响应 function verifyInNetwork(contacts: any, country: string) { const inNetworkOb = Observable .from(contacts) .map(contact => contact.p
function verifyInNetwork(contacts: any, country: string) {
const inNetworkOb = Observable
.from(contacts)
.map(contact => contact.phones)
.map(phone => verifyPhoneInNetwork(phone, country))
.first(({response}) => {
return !response.invalid && !response.exists;
})
.isEmpty()
.filter(empty => empty);
如果
verifyPhoneInNetowrk
返回一个可观察值,您应该像这样使用switchMap
:
function verifyInNetwork(contacts: any, country: string) {
const inNetworkOb = Observable
.from(contacts)
.map(contact => contact.phones)
.switchMap(phone => verifyPhoneInNetwork(phone, country))
.first(({response}) => {
return !response.invalid && !response.exists;
})
.isEmpty()
.filter(empty => empty);
了解更多信息。如果
verifyPhoneInNetowrk
返回一个可观察值,则应使用开关映射
如下:
function verifyInNetwork(contacts: any, country: string) {
const inNetworkOb = Observable
.from(contacts)
.map(contact => contact.phones)
.switchMap(phone => verifyPhoneInNetwork(phone, country))
.first(({response}) => {
return !response.invalid && !response.exists;
})
.isEmpty()
.filter(empty => empty);
了解更多关于