【发布时间】:2018-03-18 07:34:41
【问题描述】:
在这里我遇到了一个小问题,我创建了日期选择框,客户可以在其中选择 4 个选项,例如 Day,Week,Month,Custom date
1.如果客户选择Day,开始和结束日期应该是当天。
2.如果客户选择周,则从日期应从星期日开始,到日期应为周中的当前日期。
如果客户选择月份,则起始日期应为月份的开始日期,截止日期应为月份中的当前日期。
如果客户选择**自定义日期,则客户应选择他的起止日期。
下面是我的代码,我必须以下面的格式编写代码
选择日期的代码
<ion-col col-6>
<ion-label>Report Type</ion-label>
<ion-select [(ngModel)]="reportType">
<ion-option *ngFor="let opt of reportTypes" [value]="opt.TypeId">{{opt.Type}}</ion-option>
</ion-select>
</ion-col>
<ion-col col-6>
<ion-label>Report Type</ion-label>
<ion-select [(ngModel)]="reportType">
<ion-option *ngFor="let opt of reportTypes" [value]="opt.TypeId">{{opt.Type}}</ion-option>
</ion-select>
</ion-col>
</ion-row>
Code for getting custom dropdown on selecting custom
<ion-row *ngIf="reportType==10">
<ion-col>
<ion-item>
<ion-label>From Date</ion-label>
<ion-datetime displayFormat="MMM DD YYYY" pickerFormat="MMM DD YYYY" [(ngModel)]="reportDataFromDate"></ion-datetime>
</ion-item>
</ion-col>
<ion-col>
<ion-item>
<ion-label>To Date</ion-label>
<ion-datetime displayFormat="MMM DD YYYY" pickerFormat="MMM DD YYYY" [(ngModel)]="reportDataToDate"></ion-datetime>
</ion-item>
打字稿代码:
this.reportTypes=[{TypeId:1,Type:'Day'},{TypeId:7,Type:'Week'},{TypeId:30,Type:'Month'},{TypeId:10,Type:'Custom Date'}]
/////////////按reportTypes计算日期
calculateFromAndToDateByReportype(reportType){
var days; // Days you want to subtract
var currdate = new Date();
if(reportType==1){
this.reportDataFromDate=currdate;
this.reportDataToDate=currdate;
}
else {
var last = new Date(currdate.getTime() - (reportType * 24 * 60 * 60 * 1000));
this.reportDataFromDate=last;
this.reportDataToDate=currdate;
}
}
到现在为止我得到了Day,
但无法获取周,即从周日开始到本周的当天
月份:-从日期应该是月份开始日期,到日期应该是月份当前日期
当前日期:从日期应该是选定的值,到日期应该是选定的值
【问题讨论】:
标签: html angular ionic-framework ionic2