我有一个数组,我根据选择的类别打印出它的元素
<li class="thumbnail" ng-repeat="temp in templates| filter:{temp.category_id : selectedCategoryId }:true">
模板如下所示:
[{"id":"1","account_id":null,"category_id":"1","name":"Blue","thumbnail":"placehold.it/210x300","category_name":"test"},{"id":"2","account_id":null,"category_id":"1","name":"Red","thumbnail":"placehold.it/210x300","category_name":"test"},{"id":"3","account_id":null,"category_id":"2","name":"Green","thumbnail":"placehold.it/210x300","category_name":"test again"}]
感谢您的帮助!
编辑: 我还想添加一个额外的条件,即temp.category_id == null,show all。
答案 0 :(得分:2)
您无需在过滤器中再次指定temp。
更改
filter:{temp.category_id : selectedCategoryId }:true
到
filter:{category_id : selectedCategoryId }:true
这是一个工作的小提琴:http://jsfiddle.net/Sqq3s/
答案 1 :(得分:0)
您的过滤器应为:
<li ng-repeat="temp in templates | filter:{category_id : selectedCategoryId}:true"> ... </li>
编写filter: {temp.category_id : selectedCategoryId}
会在temp.category_id
对象中查找属性'temp.category_id'
(属性的无效名称,应该是temp
)。但是,您要查找属性category_id
。