如何根据输入的datepicker值(以角度为单位)通过payPeriodStartDate过滤数据

时间:2019-07-15 16:41:47

标签: javascript arrays node.js angular object

[
  {
    "processId": 876,
    "processingStatus": "Completed",
    "payPeriodStartDate": "2011-01-16T00:00:00"
  },
  {
    "processId": 875,
    "processingStatus": "Completed",
    "payPeriodStartDate": "2019-04-14T00:00:00"
  },
  {
    "processId": 874,
    "processingStatus": "Failed",
    "payPeriodStartDate": "2019-04-14T00:00:00"
  },
  {
    "processId": 873,
    "processingStatus": "Completed",
    "payPeriodStartDate": "2019-04-14T00:00:00"
  },
  {
    "processId": 872,
    "processingStatus": "Completed",
    "payPeriodStartDate": "2019-04-14T00:00:00"
  },
  {
    "processId": 871,
    "processingStatus": "Completed",
    "payPeriodStartDate": "2019-04-14T00:00:00"
  },
  {
    "processId": 870,
    "processingStatus": "Completed",
    "payPeriodStartDate": "2019-04-14T00:00:00"
  }
]

  ngOnInit() {

    this.isFetching = true;
    this.batchProcessingService.fetchPosts().subscribe(res => {
      this.data = res;
      this.dataSource = new MatTableDataSource(this.data);
      this.dataSource.sort = this.sort
      this.dataSource.paginator = this.paginator;
    }, error => {
      this.isFetching = false;
      console.log(error);
    });



  addEvent(type: string, event: MatDatepickerInputEvent<Date>) {
    // console.log(`${type}: ${event.value}`);
    const val = event.value;
    console.log(val);

    this.data.forEach(e => {
      console.log(e.payPeriodStartDate)
      let date = e.payPeriodStartDate;
      date = date.map((date) => { return new Date(date) })

      const matches = date.filter(d => {
        return d === val;
      })
      return matches;
    })
  }

0 个答案:

没有答案