gpt4 book ai didi

html - 如何使用 AngularJS orderBy

转载 作者:太空宇宙 更新时间:2023-11-04 03:31:18 24 4
gpt4 key购买 nike

我认为我的语法不正确?我可以在 Angular 中执行此操作吗?前两个过滤器有效但不是 order bys

<div class ="col-md-8 pull-left">
<span ng-click="myFilter = {green: true}">Clean</span> |
<span ng-click="myFilter = {green: false}">Dirty</span> |
<span ng-click="myFilter = orderBy: 'governance' : true">Goverance</span> |
<span ng-click="myFilter = orderBy: 'environmental' : true ">Environmental</span> |
<span ng-click="myFilter = orderBy: 'community' :true">Community</span> |
<span ng-click="myFilter = null">All</span>
</div>

<div class="list-group-item col-md-8 pull-left" ng-repeat="site in list.links | filter:myFilter">
{{site.governance}}
{{site.environmental}}
{{site.community}}
</div>

一个示例对象是

{
name: 'Facebook',
url: 'www.facebook.com',
green: false,
governance: 45,
environment: 69,
community: 72,
rank: 6
}

最佳答案

你的语法有误,你不能那样设置,filter 和 orderBy 是两个不同的过滤器,采用 2 个不同的表达式。而是在点击时设置一个顺序变量。

<div class ="col-md-8 pull-left">
...
<span ng-click=" order='governance' ">Goverance</span> |
<span ng-click=" order='environmental' ">Environmental</span> |
<span ng-click=" order='community' ">Community</span> |
...
</div>

并使用变量:-

ng-repeat="site in list.links | filter:myFilter |orderBy:order"

可能还有一种:-

 <span ng-click=" order='governance'; sort=!sort ">Goverance</span>
....
<div .. ng-repeat="site in list.links | filter:myFilter |orderBy:order:sort"

Plnkr

关于html - 如何使用 AngularJS orderBy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26269352/

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