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

  • ASUS North America

    ASUS North A

    12 AĞUSTOS 2008
  • ipsy Makeup Tips

    ipsy Makeup

    19 ŞUBAT 2009
  • TheMasterOfHell100

    TheMasterOfH

    13 AĞUSTOS 2011