android - android java 2 observable,单
问题描述
我正在尝试通过在 costructor 中为该位置传递一个位置和一个 visitCount 来创建一个新的 LocationViewModel,但为此我首先获取所有位置,然后对于每个位置,我都试图获取一个 visitCount
addDisposable(mLocationProvider.getLocation()
.flatMapSingle(locations -> Flowable.fromIterable(locations)
.flatMapSingle(singleLocation -> mVisitCountRepo.requestVisitCount(singleLocation.getId()))
.toList())
.subscribe(visitCountList -> {
}, Throwable::printStackTrace));
问题是我不知道如何将两者结合起来,所以我可以有类似的东西:
flatMapSinge(singleLocation,visitCount -> new LocationViewModel(singleLocation,visitCount).toList()
目前我在最后得到列表,任何帮助将不胜感激。
解决方案
LocationViewModel
你可以像这样在最后得到一个列表
addDisposable(mLocationProvider.getLocation().flatMap(Flowable::fromIterable)
.flatMap(singleLocation -> mVisitCountRepo.requestVisitCount(singleLocation.getId()).toFlowable()
.map(visitCount -> new LocationViewModel(singleLocation, visitCount)))
.toList()
.subscribeWith(new DisposableSingleObserver<List<LocationViewModel>>() {
@Override
public void onSuccess(List<LocationViewModel> locationViewModels) {
}
@Override
public void onError(Throwable e) {
}
}));
推荐阅读
- python - 在 pygame 'pygame.surface' 对象中出现错误不能下标
- android - 如果片段包含 AppBarLayout,BottomNavigationView 不会对片段内部的滚动做出反应
- twitter-bootstrap - Bootstrap - 对齐已关闭,不知道如何修复它
- ruby-on-rails - 每个用户的 Rails 唯一标签
- javascript - 使用php中的每个循环从两个数组中减去日期
- android - 混合应用推送通知图标未在 Android 8 (Oreo) 上显示
- kotlin - kotlin null 安全容器'是一个可变属性,此时可能已更改
- c# - 为什么默认构造函数在静态构造函数之前执行?
- node.js - Nodejs-xlsx:阅读时间问题
- python - keras lstm 中的 mfcc 错误:预期 ndim=3,发现 ndim=2