gpt4 book ai didi

javascript - Angular : show a message when no results in angular ng-repeat ?(具体情况)

转载 作者:行者123 更新时间:2023-12-02 16:34:17 25 4
gpt4 key购买 nike

我有一个特定的情况,我在 Accordion 中重复我的数据,我所需要的只是当过滤器(搜索框)在 ng-repeat="sport in sports" 上没有返回任何内容时向用户显示一条消息。

<input ng-model="query" placeholder="Search sports...">
<accordion close-others="false">
<accordion-group ng-repeat="sport in sports | filter:query"
ng-show="sport.leagues.length">
<accordion-heading>
<div ng-click="addSportToLines(sport);">
{{::sport.name}}
</div>
</accordion-heading>
<div class="list-group leagues-margin">
<a href="javascript:void(0);" class="list-group-item"
ng-repeat="league in sport.leagues"
ng-class="{active: league.active}"
ng-click="addLeagueToLines(league)">{{::league.name}}
</a>
</div>
</accordion-group>
</accordion>

最佳答案

试试这个,

<div ng-show="!(sports | filter:query).length">No items</div>

或者,我们可以通过将过滤结果分配给另一个变量来消除另一个过滤器,如下所示,

<accordion close-others="false">
<accordion-group ng-repeat="sport in filteredSports = (sports | filter: query)"
ng-show="sport.leagues.length">
<accordion-heading>
...
</accordion-group>
</accordion>

<div ng-show="!filteredSports.length">No items</div>

谢谢。

关于javascript - Angular : show a message when no results in angular ng-repeat ?(具体情况),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28051579/

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