我有预订,我想获取所有已完成且已通过的预订(〈date now的预订)
我试着根据日期按结帐属性过滤预订,但没有用,它总是显示我所有的预订列表。
这是我的Reservation
模型:
export class Reservation {
id!: number;
nb!: number;
montantTotal!: number;
user!: User;
extra!: number;
couponon!: number;
nbrooms!: number;
montantExtraRoom!: number
dateCreated!: Date
vol!: Vol;
checkin!: Date;
checkout!: Date;
persones: Persone[] = [{
titre:'',
firstname:'',
lastname:'',
datebirth:'',
nationality:'',
passport:0,
country:'',
passworddateout:'',
}]
}
这是我的组件:
export class UserMybookingComponent implements OnInit {
myres!: Reservation[]
myDate = new Date();
constructor(private reservationService: ReservationService, private datePipe: DatePipe ) {
}
ngOnInit() {
this.mybooking()
}
mybooking(){
this.reservationService.mybook().subscribe(
data => {this.myres=data;
this.myres.filter(res => new Date(res.checkout) > this.myDate)
}
)
}
}
3条答案
按热度按时间hmae6n7t1#
写入
第一个月
你忘了
this.myres =
;https://www.tutorialspoint.com/typescript/typescript_array_filter.htm
dfty9e192#
如果要显示数据,请尝试以下操作
把这放进你的html文件
bzzcjhmw3#
请始终使用getTime()或valueOf()来准确比较日期(毫秒)