在ng-repeat中反转过滤器 - AngularJS

时间:2017-01-06 09:36:11

标签: javascript angularjs angular-filters

我知道这类问题已经得到解答。但是有些事情我被困住了。

我的JSON数据如下:

[{
  "batch_queue_name": "Batch One",
  "start_date": "12/01/2016 10:18 P.M.",
  "end_date": "12/03/2016 01:08 A.M.",
  "completion_status": "100"
}, {
  "batch_queue_name": "Batch Two",
  "start_date": "12/10/2016 12:18 A.M.",
  "end_date": "12/11/2016 05:23 P.M.",
  "completion_status": "100"
}, {
  "batch_queue_name": "Batch Three",
  "start_date": "04/01/2017 12:18 A.M.",
  "end_date": "06/01/2017 03:21 P.M.",
  "completion_status": "60"
}, {
  "batch_queue_name": "Batch Four",
  "start_date": "05/01/2017 01:25 A.M.",
  "end_date": "06/01/2017 12:30 A.M.",
  "completion_status": "97"
}, {
  "batch_queue_name": "Batch Five",
  "start_date": "05/01/2017 12:18 A.M.",
  "end_date": "08/01/2017 03:37 A.M.",
  "completion_status": "42"
}, {
  "batch_queue_name": "Batch Six",
  "start_date": "16/10/2016 12:18 A.M.",
  "end_date": "18/10/2016 05:23 P.M.",
  "completion_status": "100"

}]

现在,在我的ng-repeat我试图过滤那些没有完成状态为100的那些:

<tr ng-repeat="batch in vm.batches | filter: {batch.completion_status:'!'+'100'}">
     <td> ... </td>
 </tr>

但这会引发错误:

  

语法错误:令牌'。'是意料之外的,期待[:]在第28栏   表达式[vm.batches | NaNilter:{batch.completion_status!=   '100%'}]从[.completion_status!='100%'}开始。

我做错了什么?

3 个答案:

答案 0 :(得分:2)

您不必撰写batch.completion_status。你可以这样做:

ng-repeat="batch in batches | filter: {completion_status: '!100'}"

Demo on JSFiddle

答案 1 :(得分:1)

batch.completion_status不是必需的。 只是说:

<tr ng-repeat="batch in vm.batches | filter : {completion_status:'!'+'100'}"> </tr>

答案 2 :(得分:0)

您也可以尝试这种控制器逻辑:

 $scope.filterRange = function(obj) {
    return obj.completion_status != 100;
 };