使用 angularjs 个过滤器取消选中复选框时显示所有结果
Display all results when a checkbox is unchecked with angularjs filters
我只是想做一件让我头疼的简单事情。
在 Angularjs 的应用程序中,我有一个包含值的字典。我想使用复选框过滤我的值。
如果选中该复选框,列表将使用 is_streaming : TRUE 的元素进行刷新。
但如果复选框未选中。我要显示所有结果。
目前,当复选框被选中时,它只显示好的事件(这正是我想要的)但是当我取消选中时,我只有带有 FALSE 的元素。
var events = [{
id: 0,
event_name: 'Concert 1',
is_streaming: 'true'
}, {
id: 1,
event_name: 'Concert 2',
is_streaming: 'true'
},{
id: 2,
event_name: 'Concert 3',
is_streaming: 'true'
}
<ion-toggle ng-model="is_streaming" toggle-class="toggle-calm">En ce moment</ion-toggle>
<ion-list>
<ion-item class="" ng-repeat="event in filtered=(events | filter:is_streaming)" type="item-text-wrap" href="#/tab/chats//{{event.id}}">
<div class="player" ng-show="{{event.is_streaming}} == true"></div>
</ion-item>
</ion-list>
任何帮助或建议都会很高兴听到。谢谢
所以如果你只想检查 is_streaming 的值你不需要使用过滤器,最好使用 ngIf 来做这个,看下面 CodePen :
我把一个值改成false来测试一下。
ng-if 语法:
<span ng-if"expression">display what you need </span>
编辑:
更改您的复选框属性以使用 ng-false-value 并将其设置为 null:
<ion-toggle ng-model="search.is_streaming" ng-false-value="null" toggle-class="toggle-calm">En ce moment</ion-toggle>
那么你可以使用:
<ion-item class="" ng-repeat="event in events | filter: search.is-streaming" type="item-text-wrap" href="#/tab/chats//{{event.id}}">
我只是想做一件让我头疼的简单事情。
在 Angularjs 的应用程序中,我有一个包含值的字典。我想使用复选框过滤我的值。 如果选中该复选框,列表将使用 is_streaming : TRUE 的元素进行刷新。 但如果复选框未选中。我要显示所有结果。
目前,当复选框被选中时,它只显示好的事件(这正是我想要的)但是当我取消选中时,我只有带有 FALSE 的元素。
var events = [{
id: 0,
event_name: 'Concert 1',
is_streaming: 'true'
}, {
id: 1,
event_name: 'Concert 2',
is_streaming: 'true'
},{
id: 2,
event_name: 'Concert 3',
is_streaming: 'true'
}
<ion-toggle ng-model="is_streaming" toggle-class="toggle-calm">En ce moment</ion-toggle>
<ion-list>
<ion-item class="" ng-repeat="event in filtered=(events | filter:is_streaming)" type="item-text-wrap" href="#/tab/chats//{{event.id}}">
<div class="player" ng-show="{{event.is_streaming}} == true"></div>
</ion-item>
</ion-list>
任何帮助或建议都会很高兴听到。谢谢
所以如果你只想检查 is_streaming 的值你不需要使用过滤器,最好使用 ngIf 来做这个,看下面 CodePen :
我把一个值改成false来测试一下。 ng-if 语法:
<span ng-if"expression">display what you need </span>
编辑:
更改您的复选框属性以使用 ng-false-value 并将其设置为 null:
<ion-toggle ng-model="search.is_streaming" ng-false-value="null" toggle-class="toggle-calm">En ce moment</ion-toggle>
那么你可以使用:
<ion-item class="" ng-repeat="event in events | filter: search.is-streaming" type="item-text-wrap" href="#/tab/chats//{{event.id}}">