Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.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 搜索后,调查列表不可读_Javascript_Angular_Angular Material2 - Fatal编程技术网

Javascript 搜索后,调查列表不可读

Javascript 搜索后,调查列表不可读,javascript,angular,angular-material2,Javascript,Angular,Angular Material2,我试图在startDate和endDate的基础上搜索调查列表,在startDate和endDate的基础上,它应该只返回那些包括startDate和endDate的调查。 因此,我写了一个管道,但我认为这个逻辑有问题,因为在搜索调查列表之后,根本不可读。所有这些字符串到javascript日期对象的转换在模板中相互重叠。 从“../../pipes/order by.pipe”导入{OrderByPipe}; 从“@angular/core”导入{Component,ViewChild,Ele

我试图在startDate和endDate的基础上搜索调查列表,在startDate和endDate的基础上,它应该只返回那些包括startDate和endDate的调查。 因此,我写了一个管道,但我认为这个逻辑有问题,因为在搜索调查列表之后,根本不可读。所有这些字符串到javascript日期对象的转换在模板中相互重叠。 从“../../pipes/order by.pipe”导入{OrderByPipe}; 从“@angular/core”导入{Component,ViewChild,ElementRef,OnInit}; @组成部分{ 选择器:应用程序调查信息, templateUrl:./survey-info.component.html, styleUrls:[./调查信息.component.scss] } 导出类SurveyInFoc组件实现OnInit{ @ViewChild'myCanvas'canvasRef:ElementRef; 调查记录:数组; 起始日期; 结束日期; 日期 构造函数{} 恩戈尼特{ 这是调查记录= [{surveyID:1,surveyName:survey1,日期:'1/10/2016'}, {surveyID:9,surveyName:survey9,日期:'1/12/2016'}, {surveyID:3,surveyName:survey3,日期:'9/10/2016'}, {surveyID:5,surveyName:survey5,日期:'11/10/2016'}, {surveyID:6,surveyName:survey6,日期:'16/10/2016'}, {surveyID:7,surveyName:survey7,日期:'19/10/2016'}, {surveyID:8,surveyName:survey8,日期:'21/10/2016'}, {surveyID:4,surveyName:survey4,日期:'10/10/2016'}, {surveyID:10,surveyName:survey10,日期:'1/10/2017'}, {surveyID:2,surveyName:survey2,日期:'5/10/2016'}, {surveyID:11,surveyName:survey11,日期:'5/10/2017'}, {surveyID:12,surveyName:survey12,日期:'15/10/2017'}, {surveyID:13,surveyName:survey13,日期:'25/10/2017'}]; } } //烟斗 从“@angular/core”导入{Pipe,PipeTransform}; @烟斗{ 名称:'orderBy' } 导出类OrderByPipe实现PipeTransform{ transformsurveyRecords:any,args?:any:any{ 如果args.startDate==未定义&&args.endDate==未定义{ 返回调查记录; }否则{ //console.logsurveyRecords,args.startDate,args.endDate; 设startDate=new Dateargs.startDate; 让endDate=new Dateargs.endDate; 如果开始日期和结束日期{ //console.logsurveyRecords; 如果调查记录{ 对于let i=0;i=开始日期| |调查记录[i]。日期-> 调查 {{survey.surveyName} {{调查日期}
现在可以通过进一步添加“shortDate”参数来实现此排序过滤器,如下所示: {{调查日期|日期:'shortDate'} 并将管道代码更改为:

export class OrderByPipe implements PipeTransform {
transform(surveyRecords: any, args ?: any): any {
    if (args.startDate === undefined || args.endDate === undefined) {
        return surveyRecords;
    } else if (args.startDate === null || args.endDate === null) {
        return surveyRecords;
      } else {
        const startDate = new Date(args.startDate);
        const endDate = new Date(args.endDate);
        const result = [];
        for (let i = 0; i < surveyRecords.length; i++) {
          surveyRecords[i].date = new Date(surveyRecords[i].date);
          console.log(surveyRecords[i].date);
          console.log(surveyRecords[i].date.getTime(), startDate.getTime(),
           surveyRecords[i].date.getTime(), endDate.getTime());
          if (surveyRecords[i].date.getTime() >= startDate.getTime() &&
           surveyRecords[i].date.getTime() <= endDate.getTime()) {
            const obj = { surveyID: surveyRecords[i].surveyID,
               surveyName: surveyRecords[i].surveyName,
               date: surveyRecords[i].date };
            result.push(obj);
            console.log(result);
          } else {
         console.log('no record found!!');
          }
        }
        return result;
      }}}

你能在stackblitz中重现这一点吗here@RahulSingh,给你