js 移动端上拉刷新(基于ng1)

2018-06-24 01:38:57来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

//分页下拉
var ajaxScroll = function() {
    var screenHeight = window.screen.height;
    $(document).scroll(function() {
        if (screenHeight + document.body.scrollTop >= document.body.scrollHeight) {
            $scope.pageNum = Math.ceil($scope.total / $scope.pageSize);
            if ($scope.pageNo <= $scope.pageNum) {
                $scope.pageNo++;
                $scope.tips = '正在加载数据...';
                setTimeout(function() {
                    loadData($scope.state, $scope.pageNo);
                }, 500);
                $scope.$apply();
            }
            $(document).unbind('scroll');
        }
    })

}
$scope.pageNo = 1; //第几页
$scope.pageSize = 5; //展示条数
$scope.total; //总条数
$scope.tasks = [];
$scope.state = 0;
//加载列表
function loadData(state, page) {
    $.ajax({
        type: "get",
        url: webroot + '/services/api/task/list/' + state + '?' + 'pageNo=' + $scope.pageNo + '&pageSize=' + $scope.pageSize,
        dataType: "json",
        headers: {
            'ticket': ticket
        },
        success: function(rsp) {
            if (rsp.code == 200) {
                $scope.total = rsp.result.total;
                // $scope.tasks = rsp.result.tasks;
                if ($scope.tasks) {
                    for (var i = 0; i < rsp.result.tasks.length; i++) {
                        $scope.tasks.push(rsp.result.tasks[i]);
                    }
                } else {
                    $scope.tasks = rsp.result.tasks;
                }
                if ($scope.pageNo >= (Math.ceil($scope.total / $scope.pageSize)) && rsp.result.tasks.length) {
                    $scope.tips = '已经全部加载完毕';
                } else if (!rsp.result.tasks.length) {
                    $scope.tips = '暂时没有数据';
                } else {
                    ajaxScroll();
                }
                $scope.pageNo = rsp.result.pageNo;
                $scope.$apply();
            } else {
                console.log(rsp.message)
            }
        },
        error: function(data) { console.log("error"); },
    });
};
//首次加载
loadData($scope.state, $scope.pageNo);

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:js 对象转数组

下一篇:简单谈谈js中Promise的用法