在表格中进行Angular搜索

3

我希望在表格的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>

你的 ngModel 是 search.SN,所以你的过滤器也应该是 search.SN - Krzysztof Atłasik
我按照你的建议做了,但问题仍然存在。我阅读了这个链接,看起来我所做的应该是可以的,但我不知道问题出在哪里。 https://plnkr.co/edit/?p=preview - user3122648
2个回答

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>

它不起作用。我的列表是$scope.List = {}; 我该怎么解决? - user3122648
我不明白问题出在哪里,你能展示一下 $scope.List 的元素吗? - vaqifrv
我更新了问题,您能否请检查一下? - user3122648

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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接