简体   繁体   中英

angularjs filter notarray Not an array

Hello I know that there are some post with similar title but I cannot find one that fits what I need.

I am trying to filter an array of objects on angular and its giving me the error filter notarray Not an array

Can you please help me with this The object is like

{name:"some Name",lastName:"some lastname", address:"some address"}

My goal is to filter by any field.

MY HTML INPUT BOX TO SEARCH

 <div class="input-field col s6">
  <input value="Busqueda" id="busqueda" type="text" class="validate">
  <label class="active" for="busqueda" ng-model="workerFilter.$">Busqueda</label>
</div>

MY HTML CONTENT THAT SHOULD BE FILTERED

<tr ng-repeat="data in trabajadores.worker track by $index | filter:workerFilter:strict">
        <td ng-repeat="value in trabajadores.values">
            <div class="container" ng-show="!data.editingWorker">
                {{data[value]}}
            </div>
            <div class="input-field col s4" ng-show="data.editingWorker">
                <input value="{{data[value]}}" id="{{data[value]}}_id" type="text" class="validate" ng-model="data[value]">
                <label class="active" for="{{data[value]}}_id">{{value}}</label>
            </div>
        </td>
        <td>
            <p>
                <input type="checkbox" id="{{data}}_id" ng-click="trabajadores.toggleEditing(data)" />
                <label for="{{data}}_id">Editar</label>
            </p>
        </td>
        <td>
            <i class="material-icons center black-text" ng-click="settings.deleteName(name)">delete</i>
        </td>
    </tr>

worker is assigned trought as an empty array and then with http.post call to an api on page load.

Controller:

this.worker = [];
this.getWorkers = function(){
        $http({
            method:'GET',
            url:'http://x.x.x.x:8080/api/workers/get'
        }).success(function(data){
            self.worker = [];
            data.forEach(function(element){
                var object = JSON.parse(element);
               self.worker.push(object);
            });
            console.log(self.worker); ///results pasted below
        }).error(function (err) {
            console.log(err);
        });
    };

This is a console.log and a worker example

[Object, Object, Object, Object, Object]

Array element:

0: Object lastName: "test"name: "testName"

Object Type:

Objectlength: 5__proto__: Array[0]

应用所有过滤器后, track by $index添加track by $index

ng-repeat="data in trabajadores.worker | filter:workerFilter:strict track by $index

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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