Angular 2 日期转化+多选框选择代码积累
发布时间:2020-12-17 08:39:39 所属栏目:安全 来源:网络整理
导读:日期类型从后台传过来json,是以秒的格式展现的,要把这一串数字转换成正常的日期,使用到了下边的代码: convertToDate(nows ){ var now = new Date (nows); var year = now .getFullYear(); var month = now .getMonth()+ 1 ; var date = now .getDate();
日期类型从后台传过来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<res.json().data.list.length;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)
}
} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- twitter-bootstrap – 如何使用Ember.js创建和管理Twitter
- arrays – 如何将bash数组格式化为JSON数组
- twitter-bootstrap – 将动态数据从AngularJS显示到Twitter
- 在vim中的两个命名文件之间取差异
- scala – .parallelize(…)在Apache Spark中是一个懒惰的操
- macos – 使用sudo运行时无法连接到Docker守护程序
- 实战WebService III: REST篇(基于php)
- 忽略时区Angularjs
- shell – Torch,如何用“dofile”和输入参数执行脚本?
- Scala中类型类的命名约定是什么?