我需要一长度的过滤bookshelf
这就是我所拥有的。
型号:
1.书:id,category_id
2. Bookshelf:id,book_id,read_book
<div ng-repeat = 'book in filteredBooks = (books | filter: {category_id: 5})'>
<div ng-init = 'filteredBookshelf = (bookshelf | filter: {read_book:true}).length'>
{{filteredBookshelf}}
</div>
</div>
也许我可以在控制器中过滤一些方法。例如:
$scope.bookshelfLength = $filter('filter')(bookshelf, {book.category_id: 5, read_book: true}).length
逻辑描述
I = current_user
DB中有50本不同类别的书籍。我在书架上有30个,30个中有10个有category_id:5,其中3个是read_book:true
。所以在我的情况下filteredBookshelf
应该是3
答案 0 :(得分:1)
您可以拥有类似
的内容 len = [1,2,3,4,5,6,7,8]
<div ng-repeat="l in len | filter:3 as p"> {{ l }}{{ p.length }}</div> // 3 1
在你的情况下
<div ng-repeat = 'book in filteredBooks = (books | filter: {category_id: 5}) as filtered'>
{{ filtered.length }}