角排序依据日期 [英] Angular orderBy Date

查看:120
本文介绍了角排序依据日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想通过日期Angular.js订购数组:

 < TR NG重复=呃在vm.readerFeeds |排序依据:' -  publishedDate'>
    &所述; TD> {{er.publishedDate}}&下; / TD>
< / TR>

该列表IST没有顺序的权利。我认为日期格式是什么原因?

日期格式为:

 周六,2013年11月9日4点26分55秒-0800


解决方案

要做出排序依据来工作,你需要换弦最新与的对象新的日期(/ ** /)控制器中。

例如:

  $ scope.vm.readerFeeds = [
 {
  // .....
  publishedDate:新的日期(/ *你的字符串日期* /);
  },
 {
   // .....
  publishedDate:新的日期(/ *你的字符串日期* /);
 }
];

I have an array which I want to order by date in Angular.js:

<tr ng-repeat="er in vm.readerFeeds | orderBy:'-publishedDate'">
    <td>{{er.publishedDate}}</td>
</tr>

The list ist not ordered right. I think the date format is the cause?

Date format is:

Sat, 09 Nov 2013 04:26:55 -0800

解决方案

To make to orderBy to work you need wrap string date with object of new Date(/**/) in controller.

For example:

$scope.vm.readerFeeds = [
 {
  //.....
  publishedDate: new Date(/*your string date*/);
  },
 {
   //.....
  publishedDate: new Date(/*your string date*/);
 }
];

这篇关于角排序依据日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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