Angular orderBy函数没有正确排序日期

时间:2016-01-12 21:24:44

标签: angularjs json date angularjs-filter angularjs-orderby

所以我从包含日期的JSON文件中获取数据,当我用angular调用orderBy函数时,它按错误的顺序命令日期。我导入日期字符串,然后将其更改为新的日期(myDate),但仍然没有运气,我不知道还有什么可以尝试,以便日期得到正确的排序,我看过其他帖子有关同样的事情,但没有运气提供的解决方案。当日期被排序时,它也没有任何模式,它没有按日,月或年排序,只是随机排序。所以,如果你们有任何建议,那将是非常棒的。谢谢。

JSON将日期作为此类字符串传递:

"Files":[{
 "name": "Some File",
 "path": "some/path",
 "date": "10/5/2009"
 },
 {...}]

以下是我使用的过滤器:

EmailEditor.filter('dateFormat', function myDateFormat($filter) {
return function (text) {
    var tempdate = new Date(text.replace(/-/g, "/"));
    return $filter('date')(tempdate, "M/dd/yyyy", "CST");
}
});

这是HTML:

<div class="grid_16 divElement ui-corner-all header" style="display: block;"ng-repeat="file in files | orderBy:orderItem.id:reverse">
            <div class="color" ng-model="change" ng-click="changeElem()" ng-change="colorChange()" >
                <div class="grid_2">
                    <div class="divIcon ui-corner-all"><span class="middle">{{getInitials(file.name)}}</span></div>
                </div>
                <div class="grid_14">
                    <div>{{file.name}}</div>
                    <div class="clear"></div>
                    <div class="gray">Last Modified: {{file.modDate | dateFormat}}</div>
                    <div class="clear"></div>
                    <div class="gray">Location: {{file.path}}</div>
                </div>
            </div>
        </div>

0 个答案:

没有答案
相关问题