Javascript switchMap不接受要在其内部执行的函数

Javascript switchMap不接受要在其内部执行的函数,javascript,firebase,rxjs,angularfire2,switchmap,Javascript,Firebase,Rxjs,Angularfire2,Switchmap,我尝试执行以下搜索: 我想根据第一个id搜索一些东西,这将返回一个FirebaseListObservable。然后,我尝试在可观察的的开关映射函数中执行代码,因为搜索通常需要更长的时间,否则我的代码就会完成,并且会使用lastLoc的错误值 我试着运行一系列的点,所以我在开始时循环通过一个数组 这是我的密码: evaluateRoutes() { this.currentTour.travelDistance = 0; this.currentTour.travelTime = 0;

我尝试执行以下搜索:
我想根据第一个
id
搜索一些东西,这将返回一个
FirebaseListObservable
。然后,我尝试在
可观察的
开关映射
函数中执行代码,因为搜索通常需要更长的时间,否则我的代码就会完成,并且会使用
lastLoc
的错误值

我试着运行一系列的点,所以我在开始时循环通过一个数组

这是我的密码:

evaluateRoutes() {
  this.currentTour.travelDistance = 0;
  this.currentTour.travelTime = 0;
  this.currentTour.workTime = 0;
  const locs = this.currentTour.locIds;
  let lastLoc = null;
  locs.forEach(loc => {
    console.log(lastLoc, loc);
    if (lastLoc !== null) {
      console.log('if durch', lastLoc, loc);
      this.afDb.list('routes', {
        query: {
          orderByChild: 'idStart',
          equalTo: loc
        }
      }).switchMap(items => {
        console.log('switchMap starts', lastLoc, loc);
        const filtered = items.filter(item => item.idEnd === lastLoc);
        const route = filtered[0];
        this.currentTour.routeIds.push(route.$key);
        this.currentTour.routes.push({
          idEnd: route.idEnd,
          idStart: route.idStart,
          travelDistance: route.travelDistance,
          travelTime: route.travelTime,
          tsCreated: route.tsCreated,
          userCreated: route.userCreated
        });
        this.currentTour.travelDistance = +0 + this.currentTour.travelDistance + route.travelDistance;
        this.currentTour.travelTime = +0 + this.currentTour.travelTime + route.travelTime;
      }).subscribe();
    }
    lastLoc = loc;
  });
}
我收到以下错误:

Argument of type '(items: any) => void' is not assignable to parameter of type '(value: any, index: number) => ObservableInput<{}>'.
  Type 'void' is not assignable to type 'ObservableInput<{}>'.
类型为“(items:any)=>void”的参数不能分配给类型为“(value:any,index:number)=>ObservableInput”的参数。 类型“void”不可分配给类型“ObservableInput”。
当您不需要修改Observable的流时,您应该使用Observable的
do
方法。

我通过在
开关映射
函数的末尾添加以下内容解决了我的问题:

import { Observable } from 'rxjs/Observable';
.switchMap(items => {
    ...
    return Observable.of(route);
  }).subscribe();

您没有从
switchMap
回调函数返回任何内容。我需要返回什么?我假设我不需要返回任何东西,因为我处于可观察状态。仅供参考,当我使用
map
而不是
switchMap
时,代码运行良好。传递到
map
的函数可以返回任何值-包括
undefined
-传递到
switchMap
的函数必须返回一个值,并且
undefined
不是有效的
observeibleInput
。你知道我如何解决这个问题吗这这不会很难吧?我在一个教程中看到,它以类似的方式使用。这个链接说,
observateInput接口描述了所有的值,这些值要么是subscribablepromise,要么是某种可以转换为可观察值的值集合。每个接受此接口注释的参数的运算符,也可以用于不一定是RxJS可观察的参数。
我以为我通过了
FirebaseListObservable
,因此满足了这个标准。
do
的问题是它立即执行,而在这里我需要等待
FirebaseListObservable
返回一个值。由于存在依赖关系,
do
将返回错误的值。