enter image description here请检查下面的code.angular内置过滤器工作正常。需要使用日期选择器过滤数据请帮我一样。附上参考的截图
<div class="table-responsive">
<table class="table table-bordered table-striped ">
<thead>
<tr>
<td>RECEIPT NO</td>
<td>DATE</td>
<td>NAME</td>
<td>PLACE</td>
<td>MEDIATOR NAME</td>
<td>INTEREST RATE</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="rec in records |filter:searchText |filter: date_picker">
<td>{{rec.RECEIPT_NO}}</td>
<td>{{rec.DATE}}</td>
<td>{{rec.NAME}}</td>
<td>{{rec.PLACE}}</td>
<td>{{rec.MEDIATOR_NAME}}</td>
<td>{{rec.INTEREST_RATE}}</td>
</tr>
</tbody>
</table>
</div>
Angular Code -------------------
var app = angular.module("myApp", []);
app.controller("reportingCtrl", function($scope, $http){
$scope.records = [];
$scope.ajayxCall = function() {
var url = "assets/API/api.json";
$http.get(url).then(function(response) {
$scope.records = response.data
});
};
$scope.ajayxCall();
$scope.today = function() {
$scope.dt = new Date();
};
$scope.today();
$scope.clear = function() {
$scope.dt = null;
};
$scope.toggleMin = function() {
$scope.minDate = $scope.minDate ? null : new Date();
};
$scope.toggleMin();
$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
$scope.formats = ['yyyy/MM/dd', 'dd-MMMM-yyyy', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[0];
$scope.getTime = function() {
time.getTime()
.success(function(data) {
console.log(data);
$scope.records = data.records;
})
.error(function(data, status, headers, config) {
console.log('error!');
});
};
});
答案 0 :(得分:0)
为日期创建自定义过滤器,如下所示
git log --oneline SomeSubDirectory | tail -n 1
您可以将此过滤器称为
.filter('DateFilter', function() {
return function(dataArray, date) {
if (!dataArray) {
return;
} else if (!date) {
return dataArray;
} else {
return dataArray.filter(function(item) {
var recordDate = new Date(item.DATE);
var term = recordDate.getFullYear() === date.getFullYear() &&
recordDate.getMonth() === date.getMonth() &&
recordDate.getDate() === date.getDate();
return term;
});
}
};
})