SORU
30 Mayıs 2012, ÇARŞAMBA


Nasıl AngularJS çağrı yapmak?

-Hafıza 1000 öğeleri bir veri kümesi var ve bir çağrı oluşturmak için çalışırken ben bu veri kümesi, ama bunu nasıl emin değilim.

Sonuçları filtrelemek için özel bir filtre işlevi kullanıyorum, gayet iyi çalışıyor, ama bir şekilde sayfa sayısını elde etmek istiyorum.

Herhangi bir ipucu?

CEVAP
24 Temmuz 2013, ÇARŞAMBA


Açısal UI, Bootstrap Sayfa Yönergesi

UI Bootstrapkontrol et's pagination directive. Şu anki kullanımım için yeterli özelliklere sahip ve bunun yanında thorough test spec olduğu gibi burada yayınlanan ne yerine kullandım.

Görünüm

<!-- table here -->

<pagination 
  ng-model="currentPage"
  total-items="todos.length"
  max-size="maxSize"  
  boundary-links="true">
</pagination>

<!-- items/page select here if you like -->

Denetleyicisi

todos.controller("TodoController", function($scope) {
   $scope.filteredTodos = []
  ,$scope.currentPage = 1
  ,$scope.numPerPage = 10
  ,$scope.maxSize = 5;

  $scope.makeTodos = function() {
    $scope.todos = [];
    for (i=1;i<=1000;i  ) {
      $scope.todos.push({ text:"todo " i, done:false});
    }
  };
  $scope.makeTodos(); 

  $scope.$watch("currentPage   numPerPage", function() {
    var begin = (($scope.currentPage - 1) * $scope.numPerPage)
    , end = begin   $scope.numPerPage;

    $scope.filteredTodos = $scope.todos.slice(begin, end);
  });
});

Başvuru için working plunker yaptım.


Eski Sürüm:

Görünüm

<!-- table here -->

<div data-pagination="" data-num-pages="numPages()" 
  data-current-page="currentPage" data-max-size="maxSize"  
  data-boundary-links="true"></div>

<!-- items/page select here if you like -->

Denetleyicisi

todos.controller("TodoController", function($scope) {
   $scope.filteredTodos = []
  ,$scope.currentPage = 1
  ,$scope.numPerPage = 10
  ,$scope.maxSize = 5;

  $scope.makeTodos = function() {
    $scope.todos = [];
    for (i=1;i<=1000;i  ) {
      $scope.todos.push({ text:"todo " i, done:false});
    }
  };
  $scope.makeTodos(); 

  $scope.numPages = function () {
    return Math.ceil($scope.todos.length / $scope.numPerPage);
  };

  $scope.$watch("currentPage   numPerPage", function() {
    var begin = (($scope.currentPage - 1) * $scope.numPerPage)
    , end = begin   $scope.numPerPage;

    $scope.filteredTodos = $scope.todos.slice(begin, end);
  });
});

Başvuru için working plunker yaptım.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Bart Baker

    Bart Baker

    1 Aralık 2006
  • MobileTechReview

    MobileTechRe

    6 HAZİRAN 2008
  • MVLV28

    MVLV28

    17 Mart 2008