如何显示过滤纳克重复数据的长度 [英] How to display length of filtered ng-repeat data

查看:133
本文介绍了如何显示过滤纳克重复数据的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多对象(JSON格式)的数据阵列。下面可以假设,因为这数组的内容:

I have a data array which contains many objects (JSON format). The following can be assumed as the contents of this array:

var data = [
  {
    "name": "Jim",
    "age" : 25
  },
  {
    "name": "Jerry",
    "age": 27
  }
];

现在,我显示这些细节:

Now, I display these details as:

<div ng-repeat="person in data | filter: query">
</div

下面,查询被建模到输入字段中,用户可以限制显示的数据。

Here, query is modeled to an input field in which the user can restrict the data displayed.

现在,我有我的人显示/人被显示,即显示{{data.length}}人士

Now, I have another location in which I display the current count of people / person being display, i.e Showing {{data.length}} Persons

我想要做的是,当一个人的用户搜索和显示的数据是基于查询的过滤,在显示...人也改变目前正在显示的人的价值。但它没有发生。它总是显示的数据,而不是将过滤的总人数 - ?我如何才能过滤数据计数

What I want to do is that when the user searches for a person and the data displayed is filtered based on the query, the Showing...persons also change the value of people being shown currently. But it is not happening. It always displays the total persons in data rather than the filtered one - how do I get the count of filtered data?

推荐答案

角形1.3 + (学分@汤姆)

使用的别名前pression 的(文件:的角1.3.0:ngRepeat ,向下滚动到的参数的部分):

Use an alias expression (Docs: Angular 1.3.0: ngRepeat, scroll down to the Arguments section):

<div ng-repeat="person in data | filter:query as filtered">
</div>

角形之前1.3

将结果赋予一个新的变量(如过滤),并对其进行访问:

Assign the results to a new variable (e.g. filtered) and access it:

<div ng-repeat="person in filtered = (data | filter: query)">
</div>

显示的结果数:

Showing {{filtered.length}} Persons

小提琴一个类似的例子。学分转到帕维尔·科兹洛夫斯基

这篇关于如何显示过滤纳克重复数据的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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