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) {
|
if (viewId && viewId.length > 0) {
|
||||||
return [self subModelOf:viewId];
|
return [self subModelOf:viewId];
|
||||||
} else {
|
} 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];
|
JSValue *models = [result waitUntilResult];
|
||||||
NSArray *array = [models toArray];
|
NSArray *array = [models toArray];
|
||||||
[array enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
|
[array enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
|
||||||
NSString *thisViewId = obj[@"id"];
|
NSString *thisViewId = obj[@"id"];
|
||||||
[self setSubModel:obj in:thisViewId];
|
[self setSubModel:obj in:thisViewId];
|
||||||
NSUInteger pos = position + idx;
|
NSUInteger pos = start + idx;
|
||||||
self.itemViewIds[@(pos)] = thisViewId;
|
self.itemViewIds[@(pos)] = thisViewId;
|
||||||
}];
|
}];
|
||||||
if (array.count > 0) {
|
NSString *viewId = self.itemViewIds[@(position)];
|
||||||
return array[0];
|
if (viewId && viewId.length > 0) {
|
||||||
|
return [self subModelOf:viewId];
|
||||||
} else {
|
} else {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user