angularjs 模糊查询

接了一个需求,通过angularjs增加一个检索栏,检索数组并在列表中显示返回后的结果,代码:
html代码:


  
{{ user.realName }}

js代码:

/*搜索开始*/
$scope.user = $scope.userlist;//待搜索数组
$scope.searchCont = {};//搜索内容
$scope.searchName = [];//搜索后页面遍历显示的数组  
$scope.search = function () {
  $scope.searchName = []; //每次搜索先清空数组内容  
  var searchValue = document.getElementById('search').value;
  for (var i = 0; i < $scope.user.length; i++) {
    if ($scope.user[i].realName.indexOf(searchValue) >= 0) {
      $scope.searchName.push($scope.user[i]);
    }
  }
  if (!searchValue) {
    $scope.userlist = $scope.user;
  } else {
    $scope.userlist = $scope.searchName;
  }
};
/*搜索结束*/

你可能感兴趣的:(angularjs 模糊查询)