I'm getting two items back from my API, one has a startDate
and one has an endDate
and I was wondering if it's possible to order them by their parameter string?
我从我的API中获取了两个项目,一个有startDate,另一个有endDate,我想知道是否可以通过参数字符串对它们进行排序?
Data:
数据:
[
{
name: "Item 1",
type: "Start Time"
},
{
name: "Item 2",
type: "End Time"
}
]
Something like so:
像这样的东西:
<li ng-repeat="item in items | orderBy: type='Start Time'">{{ item.name }}</li>
Is is possible using Angular's orderBy filter?
可以使用Angular的orderBy过滤器吗?
Any help is appreciated.
任何帮助表示赞赏。
2 个解决方案
#1
4
No need to specify StartTime,
无需指定StartTime,
<li ng-repeat="item in items | orderBy: 'type'>{{ item.name }}</li>
Here is the working Application
这是工作申请表
#2
1
You only need to specify the key by which you want to order in your orderBy
:
您只需要在订单中指定要订购的密钥:
orderBy: 'type'
And if you want to reverse the order use -
:
如果你想颠倒订单使用 - :
orderBy: '-type'
#1
4
No need to specify StartTime,
无需指定StartTime,
<li ng-repeat="item in items | orderBy: 'type'>{{ item.name }}</li>
Here is the working Application
这是工作申请表
#2
1
You only need to specify the key by which you want to order in your orderBy
:
您只需要在订单中指定要订购的密钥:
orderBy: 'type'
And if you want to reverse the order use -
:
如果你想颠倒订单使用 - :
orderBy: '-type'