這篇文章主要介紹了angularjs如何實現(xiàn)分頁和搜索功能,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

成都創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供澗西網(wǎng)站建設(shè)、澗西做網(wǎng)站、澗西網(wǎng)站設(shè)計、澗西網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、澗西企業(yè)網(wǎng)站模板建站服務(wù),十多年澗西做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
1、js屬于一種解釋性腳本語言;2、在絕大多數(shù)瀏覽器的支持下,js可以在多種平臺下運行,擁有著跨平臺特性;3、js屬于一種弱類型腳本語言,對使用的數(shù)據(jù)類型未做出嚴格的要求,能夠進行類型轉(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}} 條記錄/當前第 {{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è)置當前頁是 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)分頁和搜索功能”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習!
分享文章:angularjs如何實現(xiàn)分頁和搜索功能
標題路徑:http://chinadenli.net/article38/iighpp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、企業(yè)網(wǎng)站制作、網(wǎng)站改版、定制網(wǎng)站、網(wǎng)站設(shè)計公司、標簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)