当数据加载完停止ion-infinite-scroll

html代码:

<ion-infinite-scroll on-infinite="appendBike()" distance="1%" immediate-check="false" ng-if="moreDataCanBeLoaded()">
ion-infinite-scroll>
js代码:

apendBike:

/**
 * @动态加载函数
 */
function appendBike() {
    var skip = $scope.allStation.length;
    var p = null;
    if ($scope.item == "" || $scope.item == undefined) {//item 为查询条件
        p = null;
    } else {
        p = {address: $scope.item}//address为对象的属性
    }
    database.select('bikeStation', p, skip, 10).then(function (data) {//查询满足条件p的skip开始,
        $scope.allStation = $scope.allStation.concat(data);
        $scope.$broadcast('scroll.infiniteScrollComplete');//
scroll.infiniteScrollComplete
参数是一个事件名 console. log( '全部自行x车站点:', $scope. allStation. length); });}

/**
 * 是否显示加载图标
 * @returns {boolean}
 */
function moreDataCanBeLoaded(){
    var p = null;
    if ($scope.item == "" || $scope.item == undefined) {
        p = null;
    } else {
        p = {address: $scope.item}
    }
    database.fuzzyQuery("bikeStation",p).then(function(data){//模糊查询查询所有的满足条件的记录
        if(data.length>$scope.allStation.length){//如果显示的条数比总的记录数要小,设置flag为真
            $scope.flag = true;
        }else{
            $scope.flag = false;
        }
    },function(){
        $scope.flag = false;
    })
    return $scope.flag;//返回结果
}

你可能感兴趣的:(ionic)