0

我使用过 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 );
};
4

1 回答 1

0

就像任何无限滚动元素应该做的那样,ng-infinite-scroll加载的数据多于一次显示的数据。这是为了防止必须减少数据并使用户到达底部,即使还有一些数据。您可以清楚地看到这个演示中的效果。即使页面底部还有一些空间,它也会开始加载数据。

于 2016-02-11T14:21:50.933 回答