我对自己的方法有些怀疑。我有两种类型的 Observable:
//I can fetch from the server the houses and save them in the database
func houses() -> Observable<[House]>
//Given a houseId, I can fetch it's details and save them in the database
func houseDetail(id: Int) -> Observable<Family>
我想做一个 Observable,它首先获取所有房屋,然后获取家庭。我所做的是这样的:
//I am an observable which, when I complete, all data are saved
func fetchAllHousesAndFamily() -> Observable<Any> {
var allHousesObservables: [Observable] = []
for house in houses {
allHousesObservables.append(houseDetail(house.id))
}
return Observable.combineLatest(allHousesObservables)
}
但这对于……对我来说似乎不是反应式风格,而且这似乎是一种 hack,因为我对 rx 运算符了解不足。
您在 rxworld 中有正确的方法吗?
谢谢