在表格中进行角度搜索

时间:2016-07-26 08:38:20

标签: html angularjs search angularjs-scope

我想在表格中搜索列SN。

我的表格中有很多信息,我希望能够根据SN进行搜索,但是当我添加filter时,它甚至不会加载我的表格

这就是我所做的: 在我的控制器中,我的列表已填满:

 $scope.List = {};


 MyServices.getList()
.success(function (data) {
    angular.forEach(data, function (value, index) {
            $scope.List[value.SN] = {
                Description: value.Description,
                SN: value.SN
            }
    });
})
.error(function (error) {
    $scope.status = 'Unable to load customer data: ' + error.message;
});

这是我的HTML:

<label>Search: <input ng-model="search.SN"></label>
<tr ng-repeat="V in List| filter:search">
    <td>{{V.SN}}</td>
    <td>{{V.Description}}</td>
</tr>

2 个答案:

答案 0 :(得分:2)

你必须写如下:

   <label>Search: <input ng-model="search.SN"></label>
    <tr ng-repeat="V in List| filter: {SN: search.SN}">
    <td>{{V.SN}}</td>
    <td>{{V.Description}}</td>
    </tr>

答案 1 :(得分:0)

删除输入字段上的对象声明。它将匹配输入字段上指定值的整个对象:

<label>Search: <input ng-model="search"></label>
<tr ng-repeat="V in List| filter: search">
  <td>{{V.SN}}</td>
  <td>{{V.Description}}</td>
</tr>