Home filter/search using splice
Reply: 0

filter/search using splice

user2420 Published in July 20, 2018, 5:01 am

I want to filter the results of an api response list using splice. This is the code of the api which feeds the list:

function listData (){
        $scope.list = data.data.Response;

And the HTML view:

<tr ng-repeat="info in list">

The elements of that list, are the names of brands. Then, I have another api where i have all the brands with accidents. What i'm doing is search the brands on the list of accidents. If there's a brand with accident, with splice i have to filter. This is my code so far:

$scope.pursuit = function(){

        $scope.bringItOn = allInfo.get({Id: $scope.Id})

                           for(var d = 0; d< data.Response.length; d++){
                                for(var e = 0; e< $scope.list.length; e++){
                                   if(data.Response[d].Id == $scope.list[e].Id){
                                       $scope.cut = $scope.list.splice($scope.list, 1);




allInfo.get is declared on my factory. This is the HTML view for the search:

    <div class="x input-group">
<input type="text" class="form-control" placeholder="Search here!" ng-model="Id">
<span class="input-group-btn">
 <button class="btn btn-info" type="button" ng-click="pursuit()">Search</button>

The code seems to work but not as i want. Per example, let's supose i have three values:

1 Mars
2 Volvo
3 Pepsi

If I search "Mars", it splice the first value -which is Mars-. If i search "Pepsi", it splice Mars and Volvo, and shows only Pepsi. As i see, is "deleting" the first value.

What can i do to make my code works fine and splice all the brands except the value that i'm searching?

Hope you can help me.

I'm using angularjs, javascript and bootstrap.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.31546 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO