简体   繁体   English

在Angular.js中的ng-repeat中按数据类型过滤项目

[英]Filter items by data type in ng-repeat in Angular.js

Is it possible to filter a collection of items by data type (not by value) using the ng-repeat directive in Angular.js? 是否可以使用Angular.js中的ng-repeat指令按数据类型(而不是按值)过滤项目集合?

I have a custom data type via a constructor called BookCollection. 我通过一个名为BookCollection的构造函数有一个自定义数据类型。 Each property is a Book object accessible by an ID. 每个属性都是可通过ID访问的Book对象。 The BookCollection has some additional 'private' properties though that I don't want to iterate over in ng-repeat. 尽管我不想在ng-repeat中进行迭代,但BookCollection还具有一些其他“私有”属性。

<tr ng-repeat="(id, book) in library.books">

Yes you can filter using filter directive. 是的,您可以使用filter指令进行过滤。 you can provide a call back or you can use string for filter. 您可以提供回叫,也可以使用字符串进行过滤。 see this link 看到这个链接

ng-repeat="item in items|filter:'filterstring'"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM