iOS:fetch batchedItems move to previous until not empty
This commit is contained in:
parent
56d5646d65
commit
bce9350959
@ -169,17 +169,24 @@ - (NSDictionary *)itemModelAt:(NSUInteger)position {
|
||||
if (viewId && viewId.length > 0) {
|
||||
return [self subModelOf:viewId];
|
||||
} else {
|
||||
DoricAsyncResult *result = [self callJSResponse:@"renderBunchedItems", @(position), @(self.batchCount), nil];
|
||||
NSInteger batchCount = self.batchCount;
|
||||
NSInteger start = position;
|
||||
while (start > 0 && self.itemViewIds[@(start - 1)] == nil) {
|
||||
start--;
|
||||
batchCount++;
|
||||
}
|
||||
DoricAsyncResult *result = [self callJSResponse:@"renderBunchedItems", @(start), @(batchCount), nil];
|
||||
JSValue *models = [result waitUntilResult];
|
||||
NSArray *array = [models toArray];
|
||||
[array enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
|
||||
NSString *thisViewId = obj[@"id"];
|
||||
[self setSubModel:obj in:thisViewId];
|
||||
NSUInteger pos = position + idx;
|
||||
NSUInteger pos = start + idx;
|
||||
self.itemViewIds[@(pos)] = thisViewId;
|
||||
}];
|
||||
if (array.count > 0) {
|
||||
return array[0];
|
||||
NSString *viewId = self.itemViewIds[@(position)];
|
||||
if (viewId && viewId.length > 0) {
|
||||
return [self subModelOf:viewId];
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
|
Reference in New Issue
Block a user