与AngularJS NG-重复排序依据布尔值 [英] OrderBy boolean value with AngularJS ng-repeat

查看:146
本文介绍了与AngularJS NG-重复排序依据布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够通过一个变量是否是真还是假排序。

I'd like to be able to sort by whether a variable is true or false.

让我们说我们有一个变量,像这样:

Let's say we have a variable like so:

groups = {
    { name: 'first', value: true },
    { name: 'second', value: false },
    { name: 'third', value: true },
    { name: 'fourth', value: false }
}

,我们可以通过它循环,像这样:

And we can loop through it like so:

<div ng-repeat="group in groups">
    {{group.name}} {{group.value}}
</div>

这将给你如下:

first true
second false
third true
fourth false

但是,如果我想的排序布尔值的话,我可以这样做:

<div ng-repeat="group in groups | filter:{value:true}">
    {{group.name}} {{group.value}}
</div>
<div ng-repeat="group in groups | filter:{value:false}">
    {{group.name}} {{group.value}}
</div>

这将使我下面的输出(我想):

Which would give me the following output (which I want):

first true    
third true
second false
fourth false

有没有办法做到这一点使用排序依据过滤在一个纳克-repeat

推荐答案

使用变量名obeject而不是

use variable name instead obeject

orderBy:'Event':false

您会得到像期望的输出 -

you will get the desired output like -

first true    
third true
second false
fourth false

这篇关于与AngularJS NG-重复排序依据布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆