android rxjava链接调用flatmap返回null

时间:2018-07-17 12:44:23

标签: android firebase rx-java

以下,我正在使用rx java从firebase中获取位置列表,因为我必须显示该位置以及相同持续时间的visitCount,因此出现以下代码:

mLocationProvider.getLocation()
            .flatMapSingle(locations -> Flowable.fromIterable(locations)
                    .flatMapSingle(location -> mVisitCountRepo.requestVisitCount(location.getId())
                            .map(localVisitCount -> new LocationViewModel(location, localVisitCount.getValue())))
                    .toList())

如您所见,我正在获取位置列表,对于每个位置,我都会获取visitCount。但是我有一个问题,如果添加了新位置但未设置visitCount,则rx不会跳过。我想要的是如果没有visitCount对象映射到某个位置,则visitCount为0。

任何帮助将不胜感激

0 个答案:

没有答案