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写成函数,但是没搞定
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