gpt4 book ai didi

javascript - ng-repeat 过滤器是空循环

转载 作者:行者123 更新时间:2023-11-29 18:03:31 24 4
gpt4 key购买 nike

我做了下面的 ng-repeat 循环,效果很好!

<div ng-repeat="einschItem in einschaetzungen.alldata | filter: { savedatum: lolatage[tagarrayindex].tagestring } | orderBy : '-savetimestamp'">

现在我想检查 filtered 是否为空,所以我搜索并找到了这种方法应该如何解决我的问题。

<div ng-repeat="einschItem in einschaetzungen.alldata = (values | filter: { savedatum: lolatage[tagarrayindex].tagestring } | orderBy : '-savetimestamp')">

{{values.length}}

但是如果使用这段代码,我不会再在循环中得到任何结果,“einschItem”是空的。

谢谢!

我使用 angular v1.4.6

最佳答案

可能在这里想要的是为重复的结果添加别名。来自Angular Documentation :

variable in expression as alias_expression – You can also provide an optional alias expression which will then store the intermediate results of the repeater after the filters have been applied. Typically this is used to render a special message when a filter is active on the repeater, but the filtered result set is empty.

For example: item in items | filter:x as results will store the fragment of the repeated items as results, but only after the items have been processed through the filter.

Please note that as [variable name] is not an operator but rather a part of ngRepeat micro-syntax so it can be used only at the end (and not as operator, inside an expression).

For example: item in items | filter : x | orderBy : order | limitTo : limit as results.

所以在你的情况下,你可以使用:

<div ng-repeat="einschItem in einschaetzungen.alldata | 
filter: { savedatum: lolatage[tagarrayindex].tagestring } |
orderBy : '-savetimestamp'
as filteredItems">

{{filteredItems.length}}

请注意,这在功能上与问题的其他答案中提供的语法相同;这只是 ngRepeat 微语法提供的替代方案。

关于javascript - ng-repeat 过滤器是空循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33153221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com