【问题标题】:Angular search in a table表格中的角度搜索
【发布时间】:2016-11-29 19:25:20
【问题描述】:

我想对表中的 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
  • 我按照你的建议做了,但仍然是同样的问题。我已阅读此链接,看来我所做的应该可以工作,但我不知道问题出在哪里。 plnkr.co/edit/?p=preview

标签: html angularjs search angularjs-scope


【解决方案1】:

你必须写如下:

   <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 = {};我该如何解决?
  • 我不明白什么问题,你能显示$scope.List元素吗?
  • 我更新了问题,请检查一下吗?
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多