我需要一个过滤的长度bookshelf
这里是我的。如何获取ng-repeat中的项目长度或带有过滤器的ng-init的长度
型号:
1.书:ID,CATEGORY_ID
2.书架: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
50书籍不同类别是在DB中。其中30本是我的书架,30本是10本,category_id:5,其中有3本是read_book:true
。所以,在我的情况filteredBookshelf
应该是3
如下回答中,'filteredBooks'是滤波阵列别名......但是,什么是需要下面的'NG-init' - 似乎靠不住 –
@NewDev是看起来不正常。我的目标是仅针对特定的书籍类别获取'filteredBookshelf'。 – Shulte
什么是书架,什么是书架与书架的关系 –