【问题标题】:Angular.js Limit Results / Search AllAngular.js 限制结果/搜索全部
【发布时间】:2014-08-12 03:06:00
【问题描述】:

使用 Angular.js

数据库有大约 8000 个结果。加载表格大约需要 3-10 秒,具体取决于 Internet 连接。

所有结果都已加载。有没有办法限制说 1000 个结果,但搜索功能全部加载?还是 Angular 有服务器端加载?

app.js 是相当默认的:

var app = angular.module('myApp', ['ui.bootstrap']);

app.filter('startFrom', function() {
    return function(input, start) {
        if(input) {
            start = +start; //parse to int
            return input.slice(start);
        }
        return [];
    }
});
app.controller('customersCrtl', function ($scope, $http, $timeout) {
    $http.get('submit/getJobs.php').success(function(data){
        $scope.list = data;
        $scope.currentPage = 1; //current page
        $scope.entryLimit = 100; //max no of items to display in a page
        $scope.filteredItems = $scope.list.length; //Initially for no filter  
        $scope.totalItems = $scope.list.length;
    });
    $scope.setPage = function(pageNo) {
        $scope.currentPage = pageNo;
    };
    $scope.filter = function() {
        $timeout(function() { 
            $scope.filteredItems = $scope.filtered.length;
        }, 10);
    };
    $scope.sort_by = function(predicate) {
        $scope.predicate = predicate;
        $scope.reverse = !$scope.reverse;
    };
});

表格行是:

<tr ng-repeat="data in filtered = (list | filter:search | orderBy : predicate :reverse) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">

请原谅我在这方面的无知。如果您需要更多代码或其他内容,请告诉我。

【问题讨论】:

    标签: jquery angularjs performance


    【解决方案1】:

    Angular 不会在服务器端进行分页。您应该限制服务器中返回的结果,请尝试以下操作:

    $http.get('submit/getJobs.php?currentPage=1&pageSize=100').success(function(data){
        $scope.list = data;
        $scope.currentPage = 1; //current page
        $scope.entryLimit = 100; //max no of items to display in a page
        $scope.filteredItems = $scope.list.length; //Initially for no filter  
        $scope.totalItems = $scope.list.length;
    });
    

    之后你不断向服务器询问更多结果,增加 currentPage 查询字符串。

    【讨论】:

      猜你喜欢
      • 2016-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-24
      • 2017-05-08
      • 1970-01-01
      • 2012-09-24
      • 1970-01-01
      相关资源
      最近更新 更多