【发布时间】:2017-06-14 09:57:13
【问题描述】:
我有两个存储库类,存储库 A 作为 Observable 的竞赛列表>。
我的 Competition 班级有一个 countryId。
我还有一个存储库 B,它返回一个国家列表作为 Observable> 或一个按 Id 的国家作为 Observable
我想检索我的比赛列表,并通过返回包含以下内容的 CountryCompetition 类以某种方式将其与各自的国家/地区合并:
class CountryCompetition {
public Country country;
public Competition competition;
}
这意味着将我的competitionService.getCompetitions() 与countryService.getCountry(competition.id) 结合起来,但我不确定如何实现这一点; merge 或 zip 采取 observable,我还没有每个国家的 ID。
mCompetitionService.getCompetitions(wrapSearch(constraint))
.flatMap(new Func1<List<Competition>, Observable<Competition>>() {
@Override
public Observable<Competition> call(List<Competition> competitions) {
return Observable.from(competitions);
}
})
.map(new Func1<Competition, CountryCompetition>() {
@Override
public CountryCompetition call(Competition competition) {
CountryCompetition c = new CountryCompetition();
c.setCompetition(competition);
//Here i would like to set the Country as well, but mCountryService.getCountryById(competition.getCountryId()) returns another observable.
return c;
}
})
.toList()
.subscribeOn(mSchedulerProvider.io())
.observeOn(mSchedulerProvider.ui())
.subscribe(subscriber);
【问题讨论】:
-
合并?可以选择吗?
-
我无法理解该帖子。我发布了一些代码,试图让我想要实现的目标更加清晰。
标签: android rx-java rx-android