角度JS ng-repeat过滤器,仅包含属性项

时间:2022-06-01 18:24:15

I have a json file with keys like

我有一个带键的json文件

[
 {
  "message": "Verify envelopes are properly loaded.",
  "hasFigure": false,
  "figureX": 0,
  "figureY": 0
 },
{
  "message": "Verify the paddle is in the down position.",
  "hasFigure": true,
  "figureX": 185,
  "figureY": 50
}
]

I need to put this into an ng-repeat but only show the items where hasFigure is true

我需要将其放入一个ng-repeat中,但只显示hasFigure为真的项。

I know it's a filter, but can't seem to get the syntax...

我知道这是一个过滤器,但似乎无法理解它的语法……

3 个解决方案

#1


0  

Why not use ng-show / ng-hide

为什么不使用ng-show / ng-hide

<div ng-repeat="item in items" ng-show="item.hasFigure"></div>

#2


3  

Your filter syntax would be

您的过滤器语法应该是

For safer side use strict checking by adding : true at the end of filter

为了更安全的一面,请严格检查,在滤镜末端加:true

<div ng-repeat="item in items | filter: {'hasFigure': true}: true"></div>

#3


0  

Have you tried something like this:

你试过这样的方法吗:

<div ng-repeat="stuff in stuffs | filter: { hasFigure: true }"> 

#1


0  

Why not use ng-show / ng-hide

为什么不使用ng-show / ng-hide

<div ng-repeat="item in items" ng-show="item.hasFigure"></div>

#2


3  

Your filter syntax would be

您的过滤器语法应该是

For safer side use strict checking by adding : true at the end of filter

为了更安全的一面,请严格检查,在滤镜末端加:true

<div ng-repeat="item in items | filter: {'hasFigure': true}: true"></div>

#3


0  

Have you tried something like this:

你试过这样的方法吗:

<div ng-repeat="stuff in stuffs | filter: { hasFigure: true }">