Angular.js //按属性值获取元素

时间:2013-11-01 23:27:19

标签: angularjs selector angularjs-ng-repeat

在json响应中有以下内容:

[
   "alt_sizes":[
      {"width":500,"height":333,"url":"http://..."},  
      {"width":400,"height":266,"url":"http://..."},
      {"width":250,"height":167,"url":"http://..."},
      {"width":100,"height":67,"url":"http://..."},
      {"width":75,"height":75,"url":"http://..."}
   ]
]

我以某种方式解析我的对象

obj.alt_sizes[0]

但是如果我想用angular.js得到具有特定宽度或高度的元素呢? 选择小的,宽度为75?

1 个答案:

答案 0 :(得分:1)

您可以使用过滤器过滤器执行此操作:

$filter('filter')($scope.items, {width:'75'})

这是一个掠夺者:http://plnkr.co/edit/mP3LLHgJSIEbe16HrO6f?p=preview