我有 2 个电话:
-
getItems()
- 返回List<Item>
,还有Item
有id
字段 -
getParam(id)
- 返回Param
我需要制作getItems()
然后getParam(id)
对于每个 Item
在List
然后需要每 Item
更新一次收到Param
我的问题是:
如何使用 RxJava 实现此目的?
api.getItems()
.flatMapIterable(new Func1<List<Item>, Iterable<Item>>() {
@Override
public Iterable<Item> call(List<Item> items) {
return items;
}
})
.flatMap(new Func1<Item, Observable<?>>() {
@Override
public Observable<?> call(Item item) {
return api.getParam(item.id)
}
}),
...
.subscribe(...);
提前致谢。
最佳答案
使用二参数flatMap
;第二个参数是一个 Func2
,它将接收原始项目和第一个参数调用的每个结果。
关于java - RxJava : update result of call with results of subsequent calls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34342511/