I am getting an array of unix epoch time which I am converting to GMT string. I want to sort the array, how can I go about it?
我正在获得一系列unix纪元时间,我将其转换为GMT字符串。我想对数组进行排序,我该怎么做呢?
for(var i in data.results) {
var date = new Date(data.results[i].lastModifiedAt*1000);
var day = date.toGMTString();
$scope.day[i] = day;
}
1 个解决方案
#1
1
Since you tag the question as angular, you can use ng-repeat
with orderBy
. Something like:
由于您将问题标记为角度,因此可以将ng-repeat与orderBy一起使用。就像是:
$scope.results = data.results.map(function(result) {
result.day = new Date(result.lastModifiedAt*1000).toGMTString()
return result;
}
And in your html:
在你的HTML中:
<div ng-repeat="result in results | orderBy:'day':true track by $index"></div>
And you will not have to use sort
而且你不必使用排序
#1
1
Since you tag the question as angular, you can use ng-repeat
with orderBy
. Something like:
由于您将问题标记为角度,因此可以将ng-repeat与orderBy一起使用。就像是:
$scope.results = data.results.map(function(result) {
result.day = new Date(result.lastModifiedAt*1000).toGMTString()
return result;
}
And in your html:
在你的HTML中:
<div ng-repeat="result in results | orderBy:'day':true track by $index"></div>
And you will not have to use sort
而且你不必使用排序