InfiniteScroll - AngularJS无效

时间:2016-06-14 15:16:32

标签: angularjs nginfinitescroll

修改

为了检查目的,我还在nextPage函数中做了一个console.log,以检查它是否被触发:

Constructor called
Copy constructor called
A:0
B:1
Copy constructor called
B2:1
Copy constructor called
C:3

似乎我得到了一个无限循环,但我不明白为什么。

=================================

我试图将infinitescroll实现到一个视图中,但出于某种原因,它只加载了最初的4个图像而没有触发其余图像。

这是我的代码:

CTRL:

$scope.nextPage = function() {
    var captureLength = $scope.captures.length;
    console.log('TRIGGER');
    if($scope.busy) {
        return;
    }
    ...
    }
};

部分:

/* ----------------------- Variables ----------------------- */    
$scope.auth = auth;
$scope.captures = [];
$scope.following = [];

$scope.allData = [];
$scope.busy = true;
var page = 0;
var step = 4;

$scope.nextPage = function() {
    var captureLength = $scope.captures.length;
    if($scope.busy) {
        return;
    }
    $scope.busy = true;
    $scope.captures = $scope.captures.concat($scope.allData.splice(page * step, step));
    page++;
    $scope.busy = false;
    if($scope.captures.length === 0) {
        $scope.noMoreData = true;
    }
};


/* ----------------------- Process Data ----------------------- */
$q.all({follows: findFollow(), users: getUsers(), captures: getAllCaptures()}).then(function(collections) {
var follows = collections.follows;
var users = collections.users;
var captures = collections.captures;
    follows.filter(function(follow) {
        return follow.follower_id === auth.profile.user_id;
        }).forEach(function(follow) {

        users.filter(function(user) {
            return user.user_id === follow.followed_id;
            }).forEach(function(user) {
                $scope.following.push(user);
        });
    });

    follows.filter(function(follow) {
        return follow.follower_id === auth.profile.user_id;
        }).forEach(function(follow) {

        captures.filter(function(capture){
            return follow.followed_id === capture.userId;
        }).forEach(function(capture){
                console.log(capture);
                $scope.allData.push(capture);
        });
    });
    $scope.nextPage();
    $scope.busy = false;
});

/* ----------------------- Retrieve Services - Data ----------------------- */
function findFollow() {
    return userApi.findFollow().then(function(res) {
        return res.data;
    });
}

function getUsers() {
    return userApi.getUsers().then(function(res) {
        return res.data.users;
    });
}

function getAllCaptures() {
    return captureApi.getAllCaptures().then(function(res) {
        return res.data;
    });
}

任何人都知道我哪里出错了? 感谢。

0 个答案:

没有答案