正如標題所說,我有一張表,其中一列是紀元日期。我正在嘗試使用'toISOString()`中的JavaScript來翻譯它,但無法弄清楚如何去做。有沒有辦法在填充表格的同時動態執行?在ng-repeat中使用toISOString()作爲紀元日期
這裏是爲了什麼,我一起工作的JS:
angular.module('myapp', [])
.controller('MainCtrl', function($scope, $http, $filter, $interval) {
var orderBy = $filter('orderBy');
$scope.savedOrder = 'name';
$scope.searchText = ''
//first http request-----------------------------------
$http.get('xxxxxxxxxxxxxx').success(function(data) {
$scope.recentalerts = data;
$scope.tempdata = data;
$scope.order('-epochtime');
});
$scope.reverse = true;
//beginning of interval--------------------------------
$interval(function() {
$http.get('xxxxxxxxxxxxx').success(function(data) {
if (!angular.equals(data, $scope.tempdata)) {
console.log("here...");
...
$scope.tempdata = data;
} //end if
});
}, 5000);
$scope.order = function(predicate) {
$scope.reverse = !$scope.reverse;
$scope.recentalerts = orderBy($scope.recentalerts, predicate, $scope.reverse);
$scope.savedOrder = predicate;
};
});
這裏是表體:
<tbody>
<tr data-ng-repeat="alert in recentalerts | orderBy:savedOrder:reverse | filter:searchText">
<td ng-click="search(alert.epochtime)">{{alert.epochtime}}</td>
<td ng-click="search(alert.ip)">{{alert.ip}}</td>
<td ng-click="search(alert.type)">{{alert.type}}</td>
<td ng-click="search(alert.classification)">{{alert.classification}}</td>
</tr>
</tbody>
我想{{alert.epochtime.toISOString()}}
,但沒有奏效。我想在做toISOString()
之前它需要是一個日期對象,但是在ng-repeat
裏面有沒有辦法做到這一點?
哦嗨!我明白了,取得進展。我對角度瞭解不多,但也許這個鏈接會有幫助嗎? http://stackoverflow.com/questions/17925020/angularjs-convert-tag-value-unix-time-to-human-readable-time – Paul
謝謝,是啊,仍在學習:) – erp