久久久久在线观看_又色又爽又黄的免费视频播放_一区中文字幕_日韩电影在线播放

今日頭條 焦點資訊 營銷之道 企業報道 淘寶運營 網站建設 軟件開發 400電話
  當前位置: 首頁 » 資訊 » 軟件開發 » 正文

實例詳解Angular Js分頁顯示數據

放大字體  縮小字體 發布日期:2018-02-27  來源:企業800網  作者:新格網  瀏覽次數:758  【去百度看看】
核心提示:在做項目的時候我們經常會用到分頁顯示數據,其實原理很簡單:就是每次點擊(下/上)一頁的時候向后臺發送請求獲取相關JSON數據,我這里演示的是我每次請求都會傳給后臺兩個參數(pageSize–每頁要展示的數據、pageNo–當前頁碼 )

在做項目的時候我們經常會用到分頁顯示數據,其實原理很簡單:就是每次點擊(下/上)一頁的時候向后臺發送請求獲取相關JSON數據,我這里演示的是我每次請求都會傳給后臺兩個參數(pageSize–每頁要展示的數據、pageNo–當前頁碼 )

HTML相關代碼:

<p id='demo' ng-app='myApp' ng-controller='myCtrl'>
        <table>
            <thead>
                <th>序號</th>
                <th>操作人</th>
                <th>類別</th>
                <th>電話</th>
                <th>金額</th>
                <th>操作時間</th>
            </thead>
            <tbody>
            <tr ng-repeat="item in items">
                <td>{{$index+1}}</td>
                <td>{{item.operator}}</td>
                <td>{{item.type}}</td>
                <td>{{item.tell}}</td>
                <td>{{item.price}}</td>
                <td>{{item.operateTime}}</td>
            </tr>
            </tbody>
        </table>
        <p class="page">
            <span class="nextPage" ng-click="nextPage()">下一頁</span>
            <span class="prevPage" ng-click="lastPage()">上一頁</span>
            <span>{{cur}}/{{totalPage}} 頁  共 {{totalNum}} 條記錄</span>
        </p>
    </p>

CSS代碼就不貼上來了,大家自行補充;
JS代碼:

var params={
        pageSize:10,
        pageNo:1
    };var curPage=1;var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope,$http) {
   init($scope,$http);
})function search($http,$scope){
            params.pageNo=pageNo;            $http({
                method: 'GET',
                url:后臺接口地址,
                params:params
            }).then(function successCallback(response) {
                // 數據總條數
                $scope.totalNum = response.data.totalNum;                // 數據總頁數
                $scope.totalPage = response.data.totalPage;                // 數據當前頁
                $scope.cur = curPage;                // 列表詳細數據
                var content = response.data.contents;                for(var i in content){                    // 數據操作人
                    content[i].operator= content[i].operator;                    // 數據電話
                    content[i].tell= content[i].tell;                    // 數據類別
                    content[i].type = content[i].type;                    // 數據操作時間
                    content[i].operateTime = content[i].createTime;                    // 數據價格
                    content[i].price = content[i].price;
                }                $scope.items = content;
            }, function errorCallback(response) {
                // 請求失敗執行代碼
                if(response!=null)
                    error(response)
            });
        }function init($scope,$http){
        search($http,$scope);        $scope.nextPage=function(){
            nextPage($http,$scope);
        };        $scope.lastPage=function(){
            lastPage($http,$scope);
        };
    }// 點擊上一頁function lastPage($http,$scope){
    if(curPage>1){
        curPage--;
        search($http,$scope);
    }
}// 點擊下一頁function nextPage($http,$scope){
    if(curPage<totalPage){
        curPage++;
        search($http,$scope);
    }
 }

**注意**1、如果在你的項目里有根據數據前面的序號來刪除某條數據,建議看下這篇博文[Angular Js中$index的小心使用](http://blog.csdn.net/renfufei/article/details/43061877)2、如果你的項目后臺傳過來的數據沒有經過處理是全部的數據可以參考這篇博文[Angular Js表格分頁](http://www.cnblogs.com/smilecoder/p/6519833.html)

在做項目的時候我們經常會用到分頁顯示數據,其實原理很簡單:就是每次點擊(下/上)一頁的時候向后臺發送請求獲取相關JSON數據,我這里演示的是我每次請求都會傳給后臺兩個參數(pageSize–每頁要展示的數據、pageNo–當前頁碼 ),這篇文章分享一下相關內容;
HTML相關代碼:

<p id='demo' ng-app='myApp' ng-controller='myCtrl'>
        <table>
            <thead>
                <th>序號</th>
                <th>操作人</th>
                <th>類別</th>
                <th>電話</th>
                <th>金額</th>
                <th>操作時間</th>
            </thead>
            <tbody>
            <tr ng-repeat="item in items">
                <td>{{$index+1}}</td>
                <td>{{item.operator}}</td>
                <td>{{item.type}}</td>
                <td>{{item.tell}}</td>
                <td>{{item.price}}</td>
                <td>{{item.operateTime}}</td>
            </tr>
            </tbody>
        </table>
        <p class="page">
            <span class="nextPage" ng-click="nextPage()">下一頁</span>
            <span class="prevPage" ng-click="lastPage()">上一頁</span>
            <span>{{cur}}/{{totalPage}} 頁  共 {{totalNum}} 條記錄</span>
        </p>
    </p>

CSS代碼就不貼上來了,大家自行補充;
JS代碼:

var params={
        pageSize:10,
        pageNo:1
    };var curPage=1;var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope,$http) {
   init($scope,$http);
})function search($http,$scope){
            params.pageNo=pageNo;            $http({
                method: 'GET',
                url:后臺接口地址,
                params:params
            }).then(function successCallback(response) {
                // 數據總條數
                $scope.totalNum = response.data.totalNum;                // 數據總頁數
                $scope.totalPage = response.data.totalPage;                // 數據當前頁
                $scope.cur = curPage;                // 列表詳細數據
                var content = response.data.contents;                for(var i in content){                    // 數據操作人
                    content[i].operator= content[i].operator;                    // 數據電話
                    content[i].tell= content[i].tell;                    // 數據類別
                    content[i].type = content[i].type;                    // 數據操作時間
                    content[i].operateTime = content[i].createTime;                    // 數據價格
                    content[i].price = content[i].price;
                }                $scope.items = content;
            }, function errorCallback(response) {
                // 請求失敗執行代碼
                if(response!=null)
                    error(response)
            });
        }function init($scope,$http){
        search($http,$scope);        $scope.nextPage=function(){
            nextPage($http,$scope);
        };        $scope.lastPage=function(){
            lastPage($http,$scope);
        };
    }// 點擊上一頁function lastPage($http,$scope){
    if(curPage>1){
        curPage--;
        search($http,$scope);
    }
}// 點擊下一頁function nextPage($http,$scope){
    if(curPage<totalPage){
        curPage++;
        search($http,$scope);
    }
 }

**注意**1、如果在你的項目里有根據數據前面的序號來刪除某條數據,建議看下這篇博文[Angular Js中$index的小心使用](http://blog.csdn.net/renfufei/article/details/43061877)2、如果你的項目后臺傳過來的數據沒有經過處理是全部的數據可以參考這篇博文[Angular Js表格分頁](http://www.cnblogs.com/smilecoder/p/6519833.html)

相關推薦:

PHP實例代碼:AJAX 分頁顯示數據_PHP教程
jQuery+Ajax+PHP+Mysql實現分頁顯示數據實例講解_jquery

PHP實例代碼:AJAX 分頁顯示數據

以上就是實例詳解Angular Js分頁顯示數據的詳細內容,更多請關注php中文網其它相關文章!

 
 
[ 資訊搜索 ]  [ 加入收藏 ]  [ 告訴好友 ]  [ 打印本文 ]  [ 違規舉報 ]  [ 關閉窗口 ]

 
0條 [查看全部]  相關評論

 
網站首頁 | 關于我們 | 聯系方式 | 使用協議 | 版權隱私 | 網站地圖 | 排名推廣 | 廣告服務 | 積分換禮 | 網站留言 | RSS訂閱 | 吉ICP備11001726號-6
企業800網 · 提供技術支持