【问题标题】:How to search a JSON with AngularJS?如何使用 AngularJS 搜索 JSON?
【发布时间】:2014-08-27 12:12:34
【问题描述】:

这是我的工作分页:

http://plnkr.co/edit/WmC6zjD5srtYHKopLm7m

以下是我的代码摘要:

var app = angular.module('hCms', []);
app.controller('samplecontoller', function ($scope,  $http) {   
    $scope.showData = function(){   
        $scope.method = 'GET';
        $scope.url = 'homes.json';
        $scope.code = null;
        $scope.response = null;
        $scope.curPage = 0;
        $scope.pageSize = 3;

        $http({method: $scope.method,url: $scope.url}).
            success(function(data, status) {
                $scope.status = status;
                $scope.datalists = data;
            }).
            error(function(data, status) {
                $scope.datalists = data || "Request failed";
                $scope.status = status;
            });

        $scope.numberOfPages = function() {
            return Math.ceil($scope.datalists.length / $scope.pageSize);
        };

    }

});

angular.module('hCms').filter('pagination', function()
{
    return function(input, start)
    {
        start = +start;
        return input.slice(start);
    };
});

代码可以正常工作。 现在,如果您请在搜索字段中输入“Dis”,在第 3 页下有一个条目。搜索不会带来任何结果。我需要在控制器上的$scope.datalist 上运行搜索(我认为)而不是作为过滤器。

有人能给我指明正确的方向或在这件事上提供一些信息吗?

谢谢大家,

H.

【问题讨论】:

    标签: javascript json angularjs angularjs-scope filtering


    【解决方案1】:

    我遇到过这个问题 - 您必须在分页之前使用搜索过滤数据。

          <li class="paginationclass" ng-repeat="datalist in datalists | filter:search | pagination: curPage * pageSize | limitTo: pageSize ">
    

    【讨论】:

    • 你是美女。谢谢老兄。
    猜你喜欢
    • 2016-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多