如何在filterFilter($ scope.items,newVal)中的两个日期逻辑之间传递?

时间:2017-02-09 07:17:47

标签: javascript angularjs

<tr  ng-repeat="item in filtered = items |  filter:search  |startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">

角:      这里'今天'条件正常,在'上周'功能我直接在'newVal'获得exaxt结果。在这里,我怀疑如何在“filterFilter($scope.items, newVal);

中的两个日期条件之间传递
$scope.currentPage = 1;
$scope.totalItems = $scope.items.length;
$scope.entryLimit = 8; // items per page
$scope.noOfPages = Math.ceil($scope.totalItems / $scope.entryLimit);
$scope.$watch('search', function (newVal, oldVal) {

if(newVal.order_date=='today')
{ 
   var date= new Date();
   var _date = $filter('date')(new Date(date), 'MM/dd/yyyy');
   newVal.order_date=_date;
}
if(newVal.order_date=='lastweek')
{
    var today = new Date();
    var lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
    var lastWeekMonth = lastWeek.getMonth() + 1;
    var lastWeekDay = lastWeek.getDate();
    var lastWeekYear = lastWeek.getFullYear();
    var from = lastWeekMonth + "/" + lastWeekDay + "/" + lastWeekYear;
    var to = $filter('date')(new Date(today), 'MM/dd/yyyy');
    var start_date = (from && !isNaN(Date.parse(from))) ? Date.parse(from) : 0;
    var end_date = (to && !isNaN(Date.parse(to))) ? Date.parse(to) : new Date().getTime();
    newVal= $filter('filter')($scope.items, 'order_date', function(v){
        var date = new Date(v);
        return date >= moment(start_date) && date <= moment(end_date);
    }); 
}
$scope.filtered = filterFilter($scope.items, newVal);
$scope.totalItems = $scope.filtered.length;     
$scope.noOfPages = Math.ceil($scope.totalItems / $scope.entryLimit);
$scope.currentPage = 1;
}, true);

0 个答案:

没有答案