如何在AngularJS中搜索对象的所有属性中的字符串

时间:2016-11-14 14:52:01

标签: javascript angularjs

任何人都可以告诉如何在所有属性中搜索字符串。如果在某些属性中匹配,我需要在AngularJS中推送数组中的对象。

我有一个数组

$scope.ListOfPeople = [
    { PersonID: 10, FirstName: "John", LastName: "Smith", Sex: "Male" },
    { PersonID: 11, FirstName: "James", LastName: "Last", Sex: "Male" },
    { PersonID: 12, FirstName: "Mary", LastName: "Heart", Sex: "Female" },
    { PersonID: 13, FirstName: "Sandra", LastName: "Goldsmith", Sex: "Female" },
    { PersonID: 14, FirstName: "Shaun", LastName: "Sheep", Sex: "Male" },
    { PersonID: 15, FirstName: "Nicola", LastName: "Smith", Sex: "Male" }
];

如果用户在搜索文本框中键入了一些值。我需要使用PersonID,FirstName,LastName,Sex搜索所有属性,如果匹配需要推送匹配的对象。

2 个答案:

答案 0 :(得分:2)

我认为Angular的Filter过滤器可以满足您的需求

NSDateComponents *components = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]];
NSInteger currentHour = [components hour];

答案 1 :(得分:0)

那样的东西?

for(var index in $scope.ListOfPeople) { 
   if ($scope.ListOfPeople.hasOwnProperty(index)) {
       if($scope.ListOfPeople[index] == "Your string") {
           // Do something here 
       }
   }
}