I'm trying to filter the data in a table so that it only shows me the items entered on a certain date, but I can't seem to get this working. I can see the model being updated when I select a new date, but the data in the table doesn't change.
我正在尝试过滤表格中的数据,以便它只显示在特定日期输入的项目,但我似乎无法使其正常工作。我选择新日期时可以看到模型正在更新,但表中的数据不会更改。
HTML:
<tr ng-repeat='file in files | filter: date '>
Datepicker 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>
Controller:
(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();
});
})();
2 个解决方案
#1
0
You should use object for filtering.
您应该使用object进行过滤。
<tr ng-repeat='file in files | filter: date '>
$scope.date = {date: '2016-08-01'}
And every 'file' must have field 'date'
每个“文件”都必须包含字段“日期”
#2
0
So I figured out the problem. The files were in a JSON format and the date from the datepicker was a Date object.
所以我想出了问题所在。这些文件采用JSON格式,而datepicker中的日期是Date对象。
I added a listener to the controller that converts the new date to JSON and this fixed it for me:
我向控制器添加了一个监听器,将新日期转换为JSON,并为我修复了它:
$scope.$watch("date", function(newval, oldval) {
$scope.dateString = $scope.date.toJSON();
});
(and filtered using the new dateString value)
(并使用新的dateString值进行过滤)
#1
0
You should use object for filtering.
您应该使用object进行过滤。
<tr ng-repeat='file in files | filter: date '>
$scope.date = {date: '2016-08-01'}
And every 'file' must have field 'date'
每个“文件”都必须包含字段“日期”
#2
0
So I figured out the problem. The files were in a JSON format and the date from the datepicker was a Date object.
所以我想出了问题所在。这些文件采用JSON格式,而datepicker中的日期是Date对象。
I added a listener to the controller that converts the new date to JSON and this fixed it for me:
我向控制器添加了一个监听器,将新日期转换为JSON,并为我修复了它:
$scope.$watch("date", function(newval, oldval) {
$scope.dateString = $scope.date.toJSON();
});
(and filtered using the new dateString value)
(并使用新的dateString值进行过滤)