Javascript 使用md日期选择器筛选ng重复
我必须使用上载日期过滤我的Javascript 使用md日期选择器筛选ng重复,javascript,angularjs,angularjs-ng-repeat,angular-material,Javascript,Angularjs,Angularjs Ng Repeat,Angular Material,我必须使用上载日期过滤我的ng repeat项目,但它无法过滤。我什么都试过了,但总是失败。我希望有人能帮助我 控制器 ExtractionService.getUserUploadedData(d).then(function (msg) { angular.forEach(msg.data, function (val) { var src = val.uploadDate; src = src.replace(/[^0-9 +]/g, '');
ng repeat
项目,但它无法过滤。我什么都试过了,但总是失败。我希望有人能帮助我
控制器
ExtractionService.getUserUploadedData(d).then(function (msg) {
angular.forEach(msg.data, function (val) {
var src = val.uploadDate;
src = src.replace(/[^0-9 +]/g, '');
var uploadDate = new Date(parseInt(src));
console.log(uploadDate); //it returns a ISO date string format
var dd = {
uploadDate: uploadDate,
filename: val.filename,
bch: val.bch,
Id: val.edmId
}
$scope.datalistings.push(dd);
})
});
HTML
<md-datepicker ng-model="search.uploadDate" ng-change="search.uploadDate = (search.uploadDate.toISOString())" md-placeholder="Enter Date" md-open-on-focus></md-datepicker>
我还试图像这样转换
info.uploadDate
{{info.uploadDate.toISOString()},但也失败了:(有人能帮我吗?创建一个自定义的日期过滤器,如下所示
.filter('DateFilter', function() {
return function(dataArray, uploadDate) {
if (!dataArray) {
return;
} else if (!uploadDate) {
return dataArray;
} else {
return dataArray.filter(function(item) {
var uploadDateInput = new Date(item.uploadDate);
if (uploadDate !== null) {
var term = (uploadDateInput.getDate() === uploadDate.getDate() && uploadDateInput.getMonth() === uploadDate.getMonth() && uploadDateInput.getYear() === uploadDate.getYear());
return term;
}
});
}
};
});
在ng repeat
中使用它作为|DateFilter:yourinputdate
先生,我在这行中有一个错误var term=(uploadDateInput.getDate()==uploadDate.getDate()&&uploadDateInput.getMonth()==uploadDate.getMonth()&&uploadDateInput.getYear()==uploadDate.getYear());
上面写着uploadDate.getDate不是一个函数
好的,可能是uploadDate
不是日期格式,只需再添加一行var uploadDate 1=new date(uploadDate);
并与newvar uploadDate 1
进行比较,根据您使用名称即可。哦,现在没问题了,先生。非常感谢:)
.filter('DateFilter', function() {
return function(dataArray, uploadDate) {
if (!dataArray) {
return;
} else if (!uploadDate) {
return dataArray;
} else {
return dataArray.filter(function(item) {
var uploadDateInput = new Date(item.uploadDate);
if (uploadDate !== null) {
var term = (uploadDateInput.getDate() === uploadDate.getDate() && uploadDateInput.getMonth() === uploadDate.getMonth() && uploadDateInput.getYear() === uploadDate.getYear());
return term;
}
});
}
};
});