在显示或更改月份之前,我是否可以让AngularUI datepicker等到承诺完成?

时间:2021-08-06 19:40:34

I want to fetch data about the current month and then use beforeShowDay to mark some days on the datepicker. However, I would like to do it asynchronously. Is there a way to do it?

我想获取有关当前月份的数据,然后使用beforeShowDay标记datepicker上的某些天。但是,我想以异步方式进行。有办法吗?

1 个解决方案

#1


I eventually figured it out. I start the promise in the onChangeMonthYear callback an after the promise has been fulfilled I store my data and call a refresh:

我终于明白了。我在onChangeMonthYear回调中启动了承诺,在承诺完成后我存储了我的数据并调用了刷新:

this.datePickerOptions = {
    dateFormat: 'dd.mm.yy',
    onChangeMonthYear: function(year, month, inst) { 
        var input = this;

        dashboardResource.getCalendarData().then(function (data) {
            //store and/or do stuff with data;
        });
    },
    beforeShowDay: function(date) {  
        //use said data to customize each date
        return [true, className, title];
    }
}

#1


I eventually figured it out. I start the promise in the onChangeMonthYear callback an after the promise has been fulfilled I store my data and call a refresh:

我终于明白了。我在onChangeMonthYear回调中启动了承诺,在承诺完成后我存储了我的数据并调用了刷新:

this.datePickerOptions = {
    dateFormat: 'dd.mm.yy',
    onChangeMonthYear: function(year, month, inst) { 
        var input = this;

        dashboardResource.getCalendarData().then(function (data) {
            //store and/or do stuff with data;
        });
    },
    beforeShowDay: function(date) {  
        //use said data to customize each date
        return [true, className, title];
    }
}