Hi everyone, i have a problem related to the javascript async callback. I was making a load more function with backendless. I was using the async approach for better user experience.
View:
<md-list-item class="loadmorebutton" ng-disable="isloading" ng-hide="familyloadmorecounter == 0" ng-click="loadMore()">
<p>{{loadmoretextfamily}} <i class="fa fa-refresh"></i></p>
</md-list-item>
Controller:
var family = Backendless.Persistence.of( $scope.Classes.familyevent );
var build = Backendless.Persistence.of( $scope.Classes.buildingevent );
var res = Backendless.Persistence.of( $scope.Classes.familyrestaurant );
$scope.loadMore = function(){
$scope.searching = false;
$scope.isloading = true;
var dataQuery = new Backendless.DataQuery();
console.log("load more start")
switch ($scope.searchtype) {
case "family":
var callback = new Backendless.Async(
function(result)
{
console.log("callback start")
$scope.feedfamilyitem(result,true)
$scope.isloading = false;
$scope.$apply();
},
function(result)
{
console.log(result)
});
$scope.loadmoretextfamily = "Loading...";
dataQuery.options = {
offset: $scope.familyloadmorecounter
}
dataQuery.condition = $scope.familycondition
family.find( dataQuery,callback );
break;
case "building":
var callback = new Backendless.Async(
function(result)
{
console.log("callback start")
$scope.feedbuilditem(result,true)
$scope.isloading = false;
$scope.$apply();
},
function(result)
{
console.log(result)
});
$scope.loadmoretextbuild = "loading...";
dataQuery.options = {
offset:$scope.buildloadmorecounter
}
dataQuery.condition = $scope.buildcondition
build.find( dataQuery, callback);
break;
case "res":
var callback = new Backendless.Async(
function(result)
{
console.log("callback start")
$scope.feedresitem(result,true)
$scope.isloading = false;
$scope.$apply();
},
function(result)
{
console.log(result)
});
$scope.loadmoretextres = "loading...";
dataQuery.options = {
offset:$scope.resloadmorecounter
}
dataQuery.condition = $scope.rescondition
res.find( dataQuery );
break;
}
}
Call back is not working everytime, usually the first time / second time work, but not the third, fourth …etc
Thank you very much
Keen