Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用md日期选择器筛选ng重复_Javascript_Angularjs_Angularjs Ng Repeat_Angular Material - Fatal编程技术网

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);
并与new
var 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;
                }
            });
        } 
    };
});