【问题标题】:Rxjs is getting AjaxObservable instead of ajax responseRxjs 正在获取 AjaxObservable 而不是 ajax 响应
【发布时间】:2017-06-13 13:50:03
【问题描述】:

我有下一个 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);

【问题讨论】:

    标签: rxjs observable rxjs5 rxjs-dom


    【解决方案1】:

    如果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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-18
      • 2019-07-13
      • 2013-04-04
      • 2015-12-01
      相关资源
      最近更新 更多