In Angular, I need to search objects in an array

后端 未结 7 1225
时光说笑
时光说笑 2020-12-04 07:30

In Angular, I have in scope a object which returns lots of objects. Each has an ID (this is stored in a flat file so no DB, and I seem to not be able to user ng-resour

7条回答
  •  失恋的感觉
    2020-12-04 07:56

    You can use the existing $filter service. I updated the fiddle above http://jsfiddle.net/gbW8Z/12/

     $scope.showdetails = function(fish_id) {
         var found = $filter('filter')($scope.fish, {id: fish_id}, true);
         if (found.length) {
             $scope.selected = JSON.stringify(found[0]);
         } else {
             $scope.selected = 'Not found';
         }
     }
    

    Angular documentation is here http://docs.angularjs.org/api/ng.filter:filter

提交回复
热议问题