If I render the entire array like this, everything is fine :
<div class="list">
<div ng-repeat-start="chapter in chapters track by chapter.id" ng-if="chapter.analyses.length > 0" class="item item-divider">{{chapter.name}}</div>
<a ng-repeat="analysis in chapter.analyses track by analysis.id | filter:search" ng-repeat-end ng-click="viewAnalysis({{analysis.id}})" class="item">
{{analysis.name}}
</a>
</div>
<ion-infinite-scroll on-infinite="fetchAnalyses()" distance="10%"></ion-infinite-scroll>
Now I’m stuck with the fetchAnalyses() function. I don’t know how to slice my array by the analyses and keeping the current structure.
For example, if my array structure is : [Parent => [Child, Child, Child], Parent => [Child, Child]], and I decide to get 2 items with fetchAnalyses, the sliced array will be : [Parent => [Child, Child]], then the next call : [Parent => [Child, Child, Child], Parent => [Child]].
for (var i in chapters) {
var chapter= chapters[i];
var analyses = chapter.analyses;
delete chapter.analyses;
chapter.divider = true;
dataSrc = dataSrc.concat(chapter, analyses);
}
Everything works now, by fetching the elements like this :
var requestCounter = 0;
var requestLimit = 15;
var dataSrc = [];
$scope.datas = [];
$scope.hasMoreData = true;
$scope.fetchData = function() {
requestCounter++;
var start = (requestCounter - 1) * requestLimit;
var datas = dataSrc.slice(start, start + requestLimit);
$scope.datas = $scope.datas.concat(datas);
if (((requestCounter - 1) * requestLimit) > dataSrc.length)
$scope.hasMoreData = false;
$scope.$broadcast('scroll.infiniteScrollComplete');
};
Now I have a bonus question
How can I filter the entire dataSrc array and when the user clears the search input, fallback to the partially loaded list ?
EDIT :
I came up with this solution to filter an infinite list :