{"id":279620,"date":"2016-05-05T12:45:02","date_gmt":"2016-05-05T08:45:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=279620"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=279620","title":{"rendered":"\u041c\u043e\u0434\u0443\u043b\u044c \u043f\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u0439 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0430\u043d\u0433\u0443\u043b\u044f\u0440\u0430. (AngularJS)"},"content":{"rendered":"<p>       \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a: <\/p>\n<pre><code class=\"html\">&lt;idf-pagination data=&quot;paginate&quot;&gt;&lt;\/idf-pagination&gt;  <\/code><\/pre>\n<p>  \u0433\u0434\u0435 paginate \u043e\u0431\u044a\u0435\u043a\u0442 \u0432\u0438\u0434\u0430 <\/p>\n<pre><code class=\"javascript\">$scope.paginate = {  per_page: 10,  total: null,  page: 1  };  <\/code><\/pre>\n<p>  \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f $scope.paginate.page, \u043d\u0430 \u043d\u0435\u0433\u043e \u043d\u0430\u0434\u043e \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u043b\u0438\u0441\u0442\u043d\u0435\u0440 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <\/p>\n<pre><code class=\"javascript\">$scope.$watch(&quot;paginate&quot;, function(data, oldData){  if(data.page == oldData.page) return;   reloadData();  }, true);  <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0430 \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 total \u0438 \u0435\u0441\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e 1 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430. <br \/>  <a name=\"habracut\"><\/a><br \/>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 \u043c\u043e\u0434\u0443\u043b\u044f idf-pagination.js  <\/p>\n<pre><code class=\"javascript\">angular.module('idfPagination', []).directive('idfPagination', [function() {     return {         restrict: 'E',         scope: {             data: '=',             change: '='         },         template: '&lt;div class=&quot;row&quot; ng-if=&quot;data.total && data.total &gt; data.per_page&quot;&gt;' +         '    &lt;div class=&quot;col-sm-5 animated-panel&quot;&gt;' +         '        &lt;div class=&quot;dataTables_info&quot;&gt;' +         '            Showing {{(data.page - 1) * data.per_page + 1}} to {{max()}} of {{data.total}} entries' +         '        &lt;\/div&gt;' +         '    &lt;\/div&gt;' +         '    &lt;div class=&quot;col-sm-7 animated-panel&quot; ng-if=&quot;data.total &gt; data.per_page&quot;&gt;' +         '        &lt;div class=&quot;paging_simple_numbers pull-right&quot;&gt;' +         '            &lt;ul class=&quot;pagination no-margins&quot;&gt;' +         '                &lt;li class=&quot;paginate_button previous&quot; ng-class=&quot;{disabled: data.page &lt;= 1}&quot;&gt;' +         '                    &lt;a class=&quot;pointer&quot; ng-click=&quot;setPage(data.page - 1)&quot;&gt;Previous&lt;\/a&gt;' +         '                &lt;\/li&gt;' +         '                &lt;li class=&quot;paginate_button&quot; ng-repeat=&quot;num in pagesArray track by $index&quot; ng-class=&quot;{active: $index + 1 == data.page}&quot;&gt;' +         '                    &lt;a class=&quot;pointer&quot; ng-click=&quot;setPage($index + 1)&quot;&gt;{{$index + 1}}&lt;\/a&gt;' +         '                &lt;\/li&gt;' +         '                &lt;li class=&quot;paginate_button next&quot; ng-class=&quot;{disabled: data.page &gt;= numPages}&quot;&gt;' +         '                    &lt;a class=&quot;pointer&quot; ng-click=&quot;setPage(data.page + 1)&quot;&gt;Next&lt;\/a&gt;' +         '                &lt;\/li&gt;' +         '            &lt;\/ul&gt;' +         '        &lt;\/div&gt;' +         '    &lt;\/div&gt;' +         '&lt;\/div&gt;',         controller: function($scope){             $scope.$watch(&quot;data&quot;, function(data, oldData){                 if(data.total == oldData.total) return;                  $scope.numPages = Math.ceil($scope.data.total \/ $scope.data.per_page);                 $scope.pagesArray = [];                  for(var num = 0; num &lt; $scope.numPages; num++){                     $scope.pagesArray.push(num);                 }             }, true);              $scope.max = function(){                 var max = $scope.data.page * $scope.data.per_page;                 return max &lt; $scope.data.total ? max : $scope.data.total;             };              $scope.setPage = function(page){                 if(page &lt; 1 || page &gt; $scope.numPages || page == $scope.data.page) return;                  $scope.data.page = page;             };         }     }; }]); <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0443 \u0412\u0430\u0441 \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f\/\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0435 \u0441 \u0443\u0434\u043e\u0432\u043e\u043b\u044c\u0441\u0442\u0432\u0438\u0435\u043c \u0432\u044b\u0441\u043b\u0443\u0448\u0430\u0435\u043c. \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0442\u043e\u0436\u0435 \u0437\u0430\u0434\u0430\u0432\u0430\u0439\u0442\u0435, \u043e\u0442\u0432\u0435\u0442\u0438\u043c.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/282994\/\"> https:\/\/habrahabr.ru\/post\/282994\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a: <\/p>\n<pre><code class=\"html\">&lt;idf-pagination data=&quot;paginate&quot;&gt;&lt;\/idf-pagination&gt;  <\/code><\/pre>\n<p>  \u0433\u0434\u0435 paginate \u043e\u0431\u044a\u0435\u043a\u0442 \u0432\u0438\u0434\u0430 <\/p>\n<pre><code class=\"javascript\">$scope.paginate = {  per_page: 10,  total: null,  page: 1  };  <\/code><\/pre>\n<p>  \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f $scope.paginate.page, \u043d\u0430 \u043d\u0435\u0433\u043e \u043d\u0430\u0434\u043e \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u043b\u0438\u0441\u0442\u043d\u0435\u0440 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <\/p>\n<pre><code class=\"javascript\">$scope.$watch(&quot;paginate&quot;, function(data, oldData){  if(data.page == oldData.page) return;   reloadData();  }, true);  <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0430 \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 total \u0438 \u0435\u0441\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e 1 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-279620","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/279620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=279620"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/279620\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=279620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=279620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=279620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}