找NG-显示显示的列表的长度 [英] Get the length of list shown by ng-Show

查看:141
本文介绍了找NG-显示显示的列表的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Vraptor +角,问题很简单。
我藏在我的表中的某些行与NG-表演。
但我想带出的实际的行数/长度。

例:我有10个记录上$的数据。但是当我使用NG-显示,只显示5条记录。当我使用$ data.length,返回10。但是我想这回5.

我的表:

 <表中的数据-NG-表=$ tableUsuario.params>
    <&TBODY GT;
        < TR数据-NG-重复=usuario在$数据|过滤:搜索:严
         数据-NG-秀=usuario.ativo == filtroAtivo&放大器;及(filtroPerfil == NULL || usuario.perfil == filtroPerfil)>


解决方案

下面是一回事,一方面可以检查DOM,看看你有多少可见行有,这将回答你的问题,但是这是非常糟糕的解决方案,这将使你的角度应用的表现更差,而不是真正的角上下的方式做事情。

你有另一种选择是创建自己的过滤器并使用,在这种情况下,你就可以告诉你有多少项具有过滤器内。

第三个选项,这是我认为最好是创建另一个范围的变量和过滤项目填补它而已,当然你需要与你的主列表维护它同步,你可以使用<$ C做$ C> $手表和 $ watchCollection 示波器的方法

  ....
$范围。$数据= [...]功能ativoOrPerfil(项目){
  返回item.ativo == filtroAtivo&放大器;&安培; (filtroPerfil == NULL || item.perfil == filtroPerfil)}功能updateFiltered(){
   $范围。$ dataFiltered = $范围。$ data.filter(ativoOrPerfil)
}$范围。$腕表('filtroAtivo',updateFiltered)
$范围。$腕表('filtroPerfil',updateFiltered)

虽然记住,因为你使用的是严格的过滤器,然后你自己的过滤器,你将需要调整updateFiltered,包括你把所有3个条件 - 过滤器,ativo和危险

i'm using Vraptor + Angular, and the question is simple. I'm hide some rows in my table with ng-show. But i wanna take the count/length of the actual lines shown.

Exemple: I have 10 records on $data. But when i use ng-show, just show 5 records. When i use $data.length, return 10. But i wanna that return 5.

My Table:

<table data-ng-table="$tableUsuario.params">
    <tbody >
        <tr data-ng-repeat="usuario in $data | filter:search:strict" 
         data-ng-show="usuario.ativo == filtroAtivo && (filtroPerfil == null || usuario.perfil == filtroPerfil )">

解决方案

Here is the thing, on one hand you can check DOM and see how many visible rows you have, that will answer your question, but that is really bad solution, that will make performance of your angular app worse and not really angular-ish way to do things.

Another option you have is to create your own filter and use that, in this case you will be able to tell how many items you have within the filter.

Third option which is the best in my opinion is to create another scope variable and fill it in only with filtered items, of course you will need to maintain it in sync with your main list and you can do it using $watch and $watchCollection methods of your scope

.... 
$scope.$data = [ ...]

function ativoOrPerfil(item) {
  return item.ativo == filtroAtivo && (filtroPerfil == null || item.perfil == filtroPerfil )

}

function updateFiltered() {
   $scope.$dataFiltered = $scope.$data.filter(ativoOrPerfil)
}

$scope.$watch('filtroAtivo', updateFiltered)
$scope.$watch('filtroPerfil', updateFiltered)

Although keep in mind that since you are using strict filter and then your own filter, you will need to tweak updateFiltered to include all 3 conditions you have - filter, ativo and peril

这篇关于找NG-显示显示的列表的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆