搜尋

首頁  >  問答  >  主體

angular.js - angular filter 過濾陣列時,排除arr[0]怎麼做?

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>

二維數組裡面的第一列不顯示,所以在搜尋的時候需要排除arri,如果我輸入1,兩列都有的,但是我想輸入1只顯示arr[0],怎麼做啊?我將filter寫成函數,但沒搞定

为情所困为情所困2745 天前637

全部回覆(1)我來回復

  • PHPz

    PHPz2017-05-15 17:05:06

    用arr.slice(1, arr.length)

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

    好吧,題看錯了,加map就好

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

    由於angular expression不支援函數聲明,你需要把這段寫在controller裡並重新賦值給$scope.arr

    回覆
    0
  • 取消回覆