angular.js - angular filter How to exclude arr[0] when filtering an array?
为情所困
为情所困 2017-05-15 17:03:06
0
1
676
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

为情所困
为情所困

reply all(1)
PHPzhong

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template