Angular 2 日期转化+多选框选择代码积累

日期类型从后台传过来json,是以秒的格式展现的,要把这一串数字转换成正常的日期,使用到了下边的代码:

 convertToDate(nows ){   
        var now=new Date(nows);  
        var year=now.getFullYear();  
        var month=now.getMonth()+1;  
        var date=now.getDate();  
        var hour=now.getHours();  
        var minute=now.getMinutes();  
        var second=now.getSeconds();  
        return year+"年"+month+"月"+date+"日 "+hour+":"+minute+":"+second;   
    }

       convertToTime(nows ){  
        var now=new Date(nows);  
        var hour=now.getHours();  
        var minute=now.getMinutes();  
        var second=now.getSeconds();  
        return hour+":"+minute+":"+second;   
    }
 getCourse() {
    this.courseUrl=this.courseUrl+this.teacherId+"/"+this.page+"/"+this.pageSize;
    this.http.get(this.courseUrl).subscribe(res => {
      console.log(res);
        for(var i=0;i
        {  
          let startDate=this.convertToDate(res.json().data.list[i].startDate);//2017-7-23 12:32:1
          let endTime=this.convertToTime(res.json().data.list[i].endDate);//2017-8-23 13:32:1
          res.json().data.list[i].examTime=startDate+"—"+endTime;

        }
        this.data = res.json().data.list;
        this.total = res.json().data.list.length ? res.json().data.list.length : res.json().rows.length;
        this.totalPage = Math.ceil(this.total / this.pageSize);
      })

多选框的选择,选中的id放到一个数组中:

//选择班级id,根据班级id查询学生
  selectClass(id: string, capnum:string,checked: boolean) {  
    var index: number = this.classIds.indexOf(id);
    var indexCap:number=this.capacitys.indexOf(capnum)
    if (checked) {
      if (index < 0) {
        this.classIds.push(id);
        this.capacitys.push(capnum);
      }
    } else {
      if (index > -1) {
        this.classIds = this.classIds.filter((ele, index) => {
          return ele != id;
        })
        this.capacitys=this.capacitys.filter((ele, indexCap) => {
          return ele != capnum;
        })
      }
    }
    console.log(this.classIds)

    if(this.classIds.length<0){
      this.studentList=[];
    }
    else{
      //根据班级id数组查询有多少学生
      this.getStudent(this.classIds)

    }
  }

你可能感兴趣的:(♥,WEB前端,-----,【前台框架】)