过滤后如何获取ng-repeat中的项目数?

但是当我使用@ {{requestlist.length}}代码时,我得到的记录总数。而不是我需要按类别和文本搜索过滤后的记录数。

请帮我

的HTML

    <input type="text" placeholder="Search" ng-model="search">

    <label class="checkbox" for="checkboxes-@{{subcatagory.id}}" ng-repeat="subcatagory in subcategories">
        <input name="checkboxes" id="checkboxes-@{{subcatagory.id}}"   ng-click="includeCatagory(subcatagory.id)" type="checkbox">
        @{{subcatagory.titel}}
    </label>

    <div class="eol-layout-s3" ng-repeat="request in requestlist | filter:catagoryFilter | filter:search | orderBy:'titel':true">
        <div id="jobDesc-bd">
            <a href="/request/@{{request.id}}" >
                <strong>
                @{{request.titel | characters:30}}
                </strong>
            </a>

            <small>
                @{{request.message | characters:200}}
            </small>
        </div>
    </div>
<h2>count: @{{requestlist.length}}</h2>


角度的

$http.get('/api/subcategories/{{$seller->category_id}}/').success(function(subcategories){
        $scope.subcategories = subcategories;
    });
    $http.get('/api/requests/list/').success(function(requests){
        $scope.requestlist = requests;
    });

    $scope.catagoryFilter = function(cat) {
                if ($scope.catagoryIncludes.length > 0) {
                    if ($.inArray(cat.subcategorie_id, $scope.catagoryIncludes) < 0)
                        return;
                }

                return cat;
            }

最佳答案

修改

ng-repeat="request in requestlist
               | filter:catagoryFilter | filter:search | orderBy:'titel':true"




ng-repeat="request in (filterResult = (requestlist | filter:catagoryFilter
| filter:search | orderBy:'titel':true))"


长度可以通过模板中的{{filterResult.length}}或控制器中的$scope.filterResult.length访问。

注意:您可能想初始化$scope.filterResult = [];有时会出现未定义的错误。

请注意,您可以通过将过滤器后的结果分配给某些变量(如上例(filterResult))来存储过滤后的结果。然后,您可以使用此模型"filterResult"。即使在控制器$scope.filterResult中也可以使用。

07-26 01:28