您好,登錄后才能下訂單哦!
這篇文章主要介紹了angularjs如何實現(xiàn)分頁和搜索功能,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
1、js屬于一種解釋性腳本語言;2、在絕大多數(shù)瀏覽器的支持下,js可以在多種平臺下運行,擁有著跨平臺特性;3、js屬于一種弱類型腳本語言,對使用的數(shù)據(jù)類型未做出嚴(yán)格的要求,能夠進行類型轉(zhuǎn)換,簡單又容易上手;4、js語言安全性高,只能通過瀏覽器實現(xiàn)信息瀏覽或動態(tài)交互,從而有效地防止數(shù)據(jù)的丟失;5、基于對象的腳本語言,js不僅可以創(chuàng)建對象,也能使用現(xiàn)有的對象。
具體內(nèi)容如下
<html class="no-js" ng-app="myApp"> <body ng-controller="mainController"> <table class="am-table am-table-striped am-table-hover table-main"> <thead> <tr> <th>name</th> </tr> </thead> <tbody> <tr ng-repeat="item in houses | limitTo:listsPerPage"> <td>{{item.c}}</td> </tr> </tbody> </table> <div class="am-cf"> 共 {{dataNum}} 條記錄/當(dāng)前第 {{currentPage+1}} 頁 共 {{pages}} 頁 <div class="am-fr"> <ul class="am-pagination"> <li><a href="javascript:;" rel="external nofollow" rel="external nofollow" ng-click="prevPage()">«</a></li> <li><a href="javascript:;" rel="external nofollow" rel="external nofollow" ng-click="nextPage()">»</a></li> </ul> </div> </div> <script src="plugins/angularjs/angular.min.js" type="text/javascript"></script> </body> </html>
javascript
<script> var app = angular.module("myApp", []); app.controller("mainController", function ($scope, $http) { //測試數(shù)據(jù) var $data = {"fs":[{"c":"張一"},{"c":"張二"},{"c":"張三"},{"c":"張四"},{"c":"李一"},{"c":"李二"},{"c":"李三"},{"c":"李四"},{"c":"王一"},{"c":"王二"},{"c":"王三"},{"c":"王四"}]}; $scope.currentPage = 0;//設(shè)置當(dāng)前頁是 0 $scope.listsPerPage = 3;//設(shè)置每頁顯示3個 //上一頁 $scope.prevPage = function(){ if($scope.currentPage > 0){ $scope.currentPage--; } } //下一頁 $scope.nextPage = function(){ if ($scope.currentPage < $scope.pages-1){ $scope.currentPage++; } } //監(jiān)聽搜索條件 $scope.$watch('search.c', function(){ $scope.currentPage = 0; searchResult(); }); //監(jiān)聽翻頁 $scope.$watch('currentPage', function(){ searchResult(); }); //搜索或翻頁結(jié)果 function searchResult(){ var out = []; if($scope.search){ angular.forEach($data.fs,function(k,v){ if(k.c.indexOf($scope.search.c)>-1){ out.push(k); } }); } else{ out = $data.fs; } $scope.houses = out.slice($scope.currentPage*$scope.listsPerPage); $scope.dataNum = out.length; $scope.pages = Math.ceil($scope.dataNum/$scope.listsPerPage); } }); </script>
感謝你能夠認真閱讀完這篇文章,希望小編分享的“angularjs如何實現(xiàn)分頁和搜索功能”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。