search

Home  >  Q&A  >  body text

angular.js - angular filter How to exclude arr[0] when filtering an array?

js:
$scope.arr = [
["212","上","下","左","右"],
["12","1","2","3","4"],
]

html:
<input type="text" ng-model="text">

<tr ng-repeat="dataTr in arr | filter:text">
    <td ng-repeat="dataTd in dataTr">
    <ng-switch on="$first">
        <span ng-switch-when="true">{{index+1}}</span>
        <span ng-switch-default>{{dataTd}}</span>
    </ng-switch>
    </td>
</tr>

The first column in the two-dimensional array is not displayed, so you need to exclude arri when searching. If I enter 1, both columns are included, but if I enter 1, only arr[0] will be displayed. How to do this? I wrote filter as a function, but I didn’t get it done

为情所困为情所困2866 days ago686

reply all(1)I'll reply

  • PHPz

    PHPz2017-05-15 17:05:06

    Use arr.slice(1, arr.length)

    <tr ng-repeat="dataTr in arr.slice(1, arr.length) | filter:text">

    Okay, I read the question wrong, just add a map

    arr.map(function (subArr) {
      return subArr.slice(1, subArr.length);
    });

    Since angular expression does not support function declaration, you need to write this paragraph in the controller and reassign it to $scope.arr

    reply
    0
  • Cancelreply