2016-08-01 90 views
0

我想過濾表中的數據,以便它只顯示我在某個日期輸入的項目,但我似乎無法得到此工作。當我選擇新的日期時,我可以看到模型正在更新,但表中的數據不會更改。由日期不正確的JS過濾器不起作用

HTML:

<tr ng-repeat='file in files | filter: date '> 

日期選擇器HTML:

<label>From:</label> 
    <p class="input-group" style="width:200px"> 
    <input type="text" class="form-control" uib-datepicker-popup = "{{format}}" ng-model="date" is-open="status.opened" 
             min-date="minDate" max-date="maxDate" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" 
             ng-required="true" close-text="Close"/> 
     <span class="input-group-btn"> 
      <button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button> 
     </span> 
    </p> 

控制器:

(function() 
{ 
    'use strict'; 

angular.module('aml-tech-dashboard.successful-emails').controller('datepickerController', function ($scope) { 
$scope.date = ''; 
$scope.status = { 
    opened: false 
}; 

$scope.format = "yyyy-MM-dd" 
$scope.minDate = new Date(); 
$scope.dateOptions = { 
    //formatYear: 'yy', 
    startingDay: 1 
}; 

$scope.open = function ($event) { 
    $scope.status.opened = true; 

}; 

$scope.date = new Date(); 

}); 

})(); 
+0

喜,它不工作日期選擇器? – terpinmd

+0

即使我們正在談論小時或分鐘,您的列表項目的日期必須與所選日期不同 –

+0

如果日期不同,當我選擇日期時,是否所有東西都不應該從表格中消失? – Andreea

回答

0

所以我想通了這個問題。 這些文件是JSON格式的,datepicker的日期是Date對象。

我加了一個偵聽器轉換新的日期,以JSON控制器和這個固定對我來說:

$scope.$watch("date", function(newval, oldval) { 
     $scope.dateString = $scope.date.toJSON(); 
    }); 

(和使用新dateString值過濾)

0

你應該使用對象進行過濾。

<tr ng-repeat='file in files | filter: date '> 

$scope.date = {date: '2016-08-01'} 

而且每一個「文件」必須有場「約會」