我有下一个Observable我试图过滤以使用户进入网络,但.mapTo(phone => verifyPhoneInNetwork(phone,country))返回AjaxObservable而不是ajax响应
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);
答案 0 :(得分:2)
如果verifyPhoneInNetowrk
返回Observable,您应该使用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);
详细了解switchMap。