【问题标题】:How i get the count of a filterd data?我如何获得过滤数据的计数?
【发布时间】:2013-10-08 00:04:17
【问题描述】:
我有一个数据数组,我将其传递给 ng-repeat 以在现场获取数据。
我也有一个搜索模型并用它过滤数据。到目前为止效果很好,但我想在搜索字段中执行一个功能并按 Enter。这么久我有匹配的结果我想从这个条目中提醒第一个 ename 属性。当结果为 0 时,我想提醒新条目:“我写了什么”
您可以在此处看到的最小化代码:
http://jsbin.com/aDEdiJO/1/edit
【问题讨论】:
标签:
javascript
angularjs
filter
【解决方案1】:
这是您的示例工作的 JSbin:http://jsbin.com/aDEdiJO/4/edit
here 概述的方法是将您的 ng-repeat 代码更改为:
ng-repeat="entity in entities | filter:esearch"
成为:
ng-repeat="entity in selection = (entities | filter:esearch)"
然后您可以在任何地方使用:{{selection.length}} 来获取长度。