简体   繁体   English

AngularJS过滤器在对象中不起作用

[英]AngularJS filter is not working in object

My AngularJS filter is not working with an Object. 我的AngularJS过滤器不适用于对象。

View: 视图:

<input type="text" ng-model="searchKeyUser.$" placeholder="Pesquisar Chaves" class="form-control"><br>
<ul class="list-group">
    <li class="list-group-item clicavel chaves" ng-repeat="chave in keyUsers | filter:searchKeyUser" ng-class="{ active:Grupo.isActiveKey(chave.Chave.id)}" ng-click="Grupo.mostrar()">
          {{chave.Chave.chave}}{{chave.show}}
    </li>
</ul>

I tried to use searchKeyUser.$, searchKeyUser.Chave.$, searchKeyUser.Chave.chave, and nothing happened. 我尝试使用searchKeyUser。$,searchKeyUser.Chave。$,searchKeyUser.Chave.chave,但没有任何反应。 Detail: the text {{chave.Chave.chave}}{{chave.show}} is working. 详细信息:文本{{chave.Chave.chave}}{{chave.show}}正在运行。

EDIT: Js code: 编辑:Js代码:

(function() {
  var app = angular.module('groupUsers', []);
  app.controller('GroupsController', function($scope, $http){

    //Busca rel Chaves Usuarios
    $http.get(myBaseUrl + '/QlikRelKeyUser/retornoGroups').success(function(data, status, headers, config) {
      $scope.keyUsers = data;
      console.log($scope.keyUsers);
      for(x in $scope.keyUsers){
        aux = 0;
        qtd = $scope.keyUsers[x].QlikUser.length;
        for(y in $scope.keyUsers[x].QlikUser){
          aux++;
          if(qtd == 1){
            $scope.keyUsers[x].show = ' (' + $scope.keyUsers[x].QlikUser[y].nome + ')';
          }else if(aux == qtd){
            $scope.keyUsers[x].show += ', ' + $scope.keyUsers[x].QlikUser[y].nome + ')';
          }else{
            if(aux==1){
              $scope.keyUsers[x].show = ' (' + $scope.keyUsers[x].QlikUser[y].nome;
            }else{
              $scope.keyUsers[x].show += ', ' +       $scope.keyUsers[x].QlikUser[y].nome;
            }
          }
        }
      }
      console.log('');
    }).error(function(data, status, headers, config) {
      console.log('NÃO FUNFOU');
      console.log(config);
    });
    $scope.searchKeyUser = {$:''};
   });

EDIT 2: Same View: 编辑2:相同的视图:

<input type="text" ng-model="searchGroup.$" placeholder="Pesquisar Grupos" class="form-control"><br>
        <ul class="list-group" >
          <li class="list-group-item clicavel" ng-repeat="group in grupos | filter:searchGroup" ng-class="{ active:Grupo.isSet(group.QlikUserGroup.id)}" ng-click="Grupo.setActive(group.QlikUserGroup.id)">
            {{group.QlikUserGroup.nome}}
            <span class='badge bg-important'>1</span>
            <span class='badge' stylee='padding-right:30px;'>{{Grupo.totalKeys(group.QlikUserGroup.id)}}</span>
          </li>
        </ul>

Same JS: 相同的JS:

$http.get(myBaseUrl + '/QlikUserGroup/retornoGroups').success(function(data, status, headers, config) {
      $scope.grupos = data;
    }).error(function(data, status, headers, config) {
      console.log('NÃO FUNFOU');
      console.log(config);
    });

My console.log($scope.grupos); 我的console.log($scope.grupos); returns: 返回:

Array[67]
0: Object
$$hashKey: "object:530"
QlikUserGroup: Object
id: "1"
nome: "Name name name"
__proto__: Object
__proto__: Object
1: Object
2: Object
3: Object
4: Object
...

Angular filter working only with array, but you try pass object . 角度过滤器仅适用于数组,但您尝试传递object So you have at least two solutions 所以你至少有两个解决方案

  • modify server side and return array 修改服务器端并返回数组
  • make array from object in js, something like this 在js中从对象创建数组,像这样

     $scope.keyUsers = []; console.log(data); for(x in data){ var el = data[x]; $scope.keyUsers.push(el); el.show = '('+ el.QlikUser.map(function(el){ return el.nome; }).join(', ') +')'; } console.log($scope.keyUsers); 

 var data = { '1': { 'QlikUser': [{ nome: 'a' }, { nome: 'b' }, { nome: 'c' }, { nome: 'd' }, ] } } var keyUsers = []; console.log(data); for (x in data) { var el = data[x]; keyUsers.push(el); el.show = '(' + el.QlikUser.map(function(el) { return el.nome; }).join(', ') + ')'; } console.log(keyUsers); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM