ngInfiniteScroll中的一个简单错误

时间:2016-02-11 13:49:25

标签: angularjs nginfinitescroll

我使用过ngInfiniteScroll,但是我有一个小问题,我在变量项中有一组数据,例如)20但是我想在第一个视图上显示5,剩下的在滑动。但是我的代码在第一个视图中加载了所有20个,我怎么能实现这一点,我已经在下面给出了我的代码 和我的数据结构

{
"data": [ {
                "name": "Hoarding Majestic",
                "code": 456,
                "image": "assets/images/images/hoarding1.jpg",
                "location": "Majestic"


            },
            {
                "name": "BusShelter ForumMall",
                "code": 452,
                "image": "assets/images/images/hoarding2.jpg",
                "location": "Whitefield"


            },
            {
                "name": "Digital Vijayanagar",
                "code": 458,
                "image": "assets/images/images/hoarding3.jpg",
                "location": "Vijayanagar"


            },
            {
                "name": "Digital Vijayanagar",
                "code": 458,
                "image": "assets/images/images/hoarding3.jpg",
                "location": "Vijayanagar"



            }
         ]
}

HTML: -

<div layout="row" layout-align="space-around" layout-padding infinite-scroll='loadMore()' infinite-scroll-distance='2' 
                    infinite-scroll-disabled='{{busyLoadingData}}'  infinite-scroll-container = "'#content'">
<table class="simple">
<thead>
  <tr>
     <th class="secondary-text">
        <div class="table-header">
           <span class="column-title">Asset</span>
        </div>
     </th>
     <th class="secondary-text">
        <div class="table-header">
           <span class="column-title">Location</span>
        </div>
     </th>

  </tr>
  </thead>
  <tbody>
  <tr ng-repeat="assets in items">
     <!--| priceRange:slider:lower:upper-->

     <td>{{assets.name}}</td>

     <td>{{ assets.location }}</td>

  </tr>

 </tbody>
 </table>
 </div>

和我的控制员: -

$scope.data = booking.data;
$scope.busyLoadingData = false;
$scope.items = [];
$scope.loadMore = function() { 
//console.log("asdfasdfasd");
if($scope.busyLoadingData)
   return;
   $scope.busyLoadingData = true;
     var last = $scope.data[$scope.data.length - 1];
    for(var i = 0 ; i <= 5; i++) {
      $scope.items.push($scope.data[i]);
      //console.log(last);
    } 
    $timeout(function(){$scope.busyLoadingData = false; }, 3000 );
};

1 个答案:

答案 0 :(得分:0)

与任何无限滚动元素一样,ng-infinite-scroll正在加载的数据多于一次显示的数据。这是为了防止必须减少数据并使用户到达底部,即使剩下一些数据也是如此。您可以在this demo中清楚地看到效果。它将开始加载数据,即使页面底部仍有一些空间。