要建立一個完整的User
實體,我需要執行此任務:從userId
無法建立這種可觀察
- 得到一個
UserResponse
(REST API響應)從userId
得到一個
- 獲取從
UserResponse.addressId
- 一個
Address
構建從UserResponse
的User
和List<Role>
和Address
。
List<Role>
我嘗試這樣做:
public Observable<User> getUserById(String userId) {
return Observable.zip(getUserResponse(userId), getRoles(userId), new Func2<UserResponse, List<Role>, User>() {
@Override
public User call(UserResponse response, List<Role> roles) {
//I need the address here!
}
});
但我不知道如何使用AddressRepository
來從UserResponse.addressId
的Address
。
public interface AddressRepository {
Observable<Address> getAddress(String addressId);
}
的User
構造是這樣的:
public User(String userId, Address address, List<Role> roles) { ... }
我希望你能理解。很難解釋這個問題。
但是你不使用上面的'cache()'操作符 –
Whop,編輯和修復! –