Splice在forEach循环中工作

时间:2015-05-26 16:15:11

标签: javascript angularjs for-loop foreach ionic

当我尝试拼接我的数组时,它会删除错误的数组,我认为它在拼接时与forEach的索引有关。 现在试了几个小时,无法让它工作:/

     dpd.users.get(function (result) {
        $scope.persons = result;

            $scope.persons.forEach(function(entry, index) {
                dpd.timesheets.get({user:entry.id}, function (result2) {

                entry.timesheets = result2;

            //splice person if timesheets of person is empty

                if (entry.timesheets.length <=0){
                   $scope.persons.splice(index, 1);
                }

......................

0 个答案:

没有答案