AngularJs 是如何Post数据并且分页

$scope.getAPI= function(pageSize, page) {
        setTimeout(function() {
            var url=base+'/api.server.com/xxxx/sc/commodity/getxxxxx';
                $http(
                    {method:'POST',
                    url,
                    data: {'grant_type':'client_credentials'},
                    data: {'Id': '1020xx','limit':1000,'page':1},
                    status
                    }).success(function(largeLoad) {
                        $scope.setPagingData(largeLoad, page, pageSize);
                    }).error(function(largeLoad,status){
                        console.log('error'+status)
                    })
        }, 100);
    };

 $scope.setPagingData = function(dt, page, pageSize) {
        //将对象转换为数组
       var arry =  $.map((dt),function(value,index){
              return [value]
        })
       arry = arry.slice(1)
       var arr = []
       for(i = 0;i<arry.length;i++){
         arr = arry[i]
       }
       arry =  $.map((arr),function(value,index){
              return [value]
        })
        var pagedData = arry[0].slice((page - 1) * pageSize, page * pageSize);
        $scope.ports = pagedData;
        $scope.totalServerItems = dt.length;
        if (!$scope.$$phase) {
            $scope.$apply();
        }
    };

     $scope.pagingOptions = {
        pageSizes: [15, 30, 45],
        pageSize: 15,
        currentPage: 1
    };
    $scope.getAPI();//main方法调用
    原文作者:MichaelDuan
    原文地址: https://segmentfault.com/a/1190000003051214
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞