我目前的爱奥尼亚版本是4.12.0,需要一个弹出的警报从用户的输入StartDate和EndDate从用户的过滤器。我学到的是,它允许您添加“date”类型,但是,它只支持value和max值的“STRING”。另外,记住不要混合输入类型。下面是我的代码
private format_date(dt: any) {
var today = new Date(dt);
let dd: any = today.getDate();
let mm: any = today.getMonth() + 1;
const yyyy = today.getFullYear();
if (dd < 10) {
dd = `0${dd}`;
}
if (mm < 10) {
mm = `0${mm}`;
}
return `${yyyy}-${mm}-${dd}`;
}
async presentPopover() {
const dt = new Date();
this.firstDate = dt.getFullYear() + '-' + ((dt.getMonth() + 1) < 10 ? '0' + (dt.getMonth() + 1) : (dt.getMonth() + 1) ) + '-01';
this.maxDate = this.format_date(dt);
this.lastDay = new Date(dt.getFullYear(), dt.getMonth() + 2, 0);
this.lastDay = this.format_date(this.lastDay);
if(new Date(this.lastDay) > dt) {
this.lastDay = this.format_date(dt);
}
const alerts = await this.alertController.create({
header: 'Filter',
inputs: [
{
name: 'fromDt',
type: 'date',
value: this.firstDate,
max: this.maxDate
},
{
name: 'toDt',
type: 'date',
value: this.lastDay,
max: this.maxDate
}
],
buttons:
[
{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
handler: () => {
console.log('Confirm Cancel');
}
},
{
text: 'Ok',
handler: () => {
console.log('Confirm Ok');
this.fetchData();
}
}
]
});
await alerts.present();
}