How to find an object in a list by comparing on object property

后端 未结 3 1043
时光说笑
时光说笑 2021-01-27 22:13

How could I scan an array of objects in order to find an object by matching the object property:

$scope.items = [
  { id: 1, name: \'one\' }, 
  { id: 2, name: \         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-27 22:39

    You can use Angular's built-in filter functionality to perform the search:

    $scope.filteredItems = function() {
        return $filter($scope.items, id == filterID);
    }
    

    Here is a fiddle showing the filter in action: http://jsfiddle.net/wittersworld/xV8QT/

提交回复
热议问题