ng-repeat 和 orderBy 字符串
ng-repeat and orderBy a String
我从我的 API 取回了两件商品,一件有 startDate
,一件有 endDate
,我想知道是否可以按参数排序字符串?
数据:
[
{
name: "Item 1",
type: "Start Time"
},
{
name: "Item 2",
type: "End Time"
}
]
大概是这样:
<li ng-repeat="item in items | orderBy: type='Start Time'">{{ item.name }}</li>
是否可以使用 Angular 的 orderBy 过滤器?
感谢任何帮助。
您只需在 orderBy
中指定您要订购的密钥:
orderBy: 'type'
如果您想颠倒顺序,请使用 -
:
orderBy: '-type'
无需指定开始时间,
<li ng-repeat="item in items | orderBy: 'type'>{{ item.name }}</li>
这是工作Application
我从我的 API 取回了两件商品,一件有 startDate
,一件有 endDate
,我想知道是否可以按参数排序字符串?
数据:
[
{
name: "Item 1",
type: "Start Time"
},
{
name: "Item 2",
type: "End Time"
}
]
大概是这样:
<li ng-repeat="item in items | orderBy: type='Start Time'">{{ item.name }}</li>
是否可以使用 Angular 的 orderBy 过滤器?
感谢任何帮助。
您只需在 orderBy
中指定您要订购的密钥:
orderBy: 'type'
如果您想颠倒顺序,请使用 -
:
orderBy: '-type'
无需指定开始时间,
<li ng-repeat="item in items | orderBy: 'type'>{{ item.name }}</li>
这是工作Application