【问题标题】:View the size of a filtered ngRepeat array before filtering again with limitTo在使用limitTo再次过滤之前查看过滤器ng重复数组的大小
【发布时间】:2016-02-22 18:41:42
【问题描述】:

我目前正在通过自定义startAtIndex 过滤器和limitTo 过滤器的组合对我的ngRepeat 进行分页。无论页面如何,我都想显示数据集中的结果总数。但是,当您使用limitTo 时,这显然会在此时切断数组,并且您无法获得所需的长度属性。

我的ngRepeat

ng-repeat-start="colleague in pagination.filteredData = (colleagueDataArray | filter:{name: queries.name} | filter:{client: queries.client} | filter:queries.generalQuery | orderBy:sortByField:reverseSort | startFrom: pagination.startAtIndex | limitTo:pagination.pageSize)">

我将过滤器的结果分配给pagination.filteredData 对象,然后我可以使用{{pagination.filteredData.length}} 在我的控制器中的任何位置显示它的长度。

在被startAtIndexlimitBy 过滤之前,我怎样才能得到过滤数组的长度?我可以以某种方式部分过滤colleagueDataArray 数组,然后用ngRepeat 再次过滤得到的filteredArray 吗?

如果这对您没有意义,请告诉我,以便我编辑问题。

【问题讨论】:

    标签: javascript arrays angularjs pagination


    【解决方案1】:

    编写一个自定义过滤器,无论你在那里尝试什么。

    ng-repeat="data in bigData | filter:myfilter"
    
    $scope.myfilter= function(data)
    {
        // Check length or i dont know
        // $scope.bigData.length 
    
        if($scope.bigData.length > 2)
        {
            return true; // this will be listed in the results
        }
    
        return false; // otherwise it won't be within the results
    };
    

    【讨论】:

      猜你喜欢
      • 2015-10-05
      • 2016-09-23
      • 1970-01-01
      • 1970-01-01
      • 2019-06-16
      • 2023-01-02
      • 1970-01-01
      • 2015-07-16
      • 2015-01-24
      相关资源
      最近更新 更多