我之前在这个位置Javascript NoGray Calendar find next available date after chosen blocked dates if today is blocked询问了一个类似的问题,以检查单个日历。现在对于第二个日历,我试图让它检查上一个日期在my_cal1,添加一些天,我选择了7天,然后检查该日期是否可用,如果不是这样做的话第一个日历,每天检查一天,直到可用日期,然后选择该日期。因此,要明确说明,从第一个日历选择日期开始的天数并不完全固定,只有当它选择的日期可用时,如果没有,它将移至下一个可用日期。
这是我到目前为止所尝试的代码。这是第二个onLoad,我试图解决的日历2 my_cal2的onLoad:
my_cal1 = new ng.Calendar({
input: {date:'date1', month:'month1', year:'year1'},
selected_date:new Date(),
display_date:new Date(),
dates_off:[{date:1, month:0},{date:25, month:11},{date:24, month:6, year:2014},{date:27, month:6, year:2014},{date:28, month:6, year:2014},{date:29, month:6, year:2014},{date:30, month:6, year:2014},{date:31, month:6, year:2014},{date:8, month:7, year:2014},{date:9, month:7, year:2014}],
events: {
onDateClick: function(dt){
this.select_date(dt);
},
// code to check if the start date is selectable
onLoad: function(){
var st_dt = this.get_start_date().clone();
while(!this.is_selectable(st_dt)[0]){
st_dt = st_dt.from_string('today + 1');
}
// checking if no dates are selected
if (!ng.defined(this.get_selected_date())){
this.select_date(st_dt);
}
this.set_start_date(st_dt);
}
}
});
my_cal2 = new ng.Calendar({
input: {date:'date1', month:'month1', year:'year1'},
selected_date:new Date(),
display_date:new Date(),
dates_off:[{date:1, month:0},{date:25, month:11},{date:24, month:6, year:2014},{date:27, month:6, year:2014},{date:28, month:6, year:2014},{date:29, month:6, year:2014},{date:30, month:6, year:2014},{date:31, month:6, year:2014},{date:8, month:7, year:2014},{date:9, month:7, year:2014}],
events: {
onDateClick: function(dt){
this.select_date(dt);
},
// code to check if the start date is selectable
onLoad: function(){
var st_dt = this.get_start_date().clone();
console.log(this.is_selectable(st_dt)[0]);
while(!this.is_selectable(st_dt)[0])
{
st_dt = st_dt.from_string('today + 1');
}
// checking if no dates are selected
if (!ng.defined(this.get_selected_date()))
{
var stt_dt = this.select_date(st_dt.from_string('today + 7')).clone();
console.log(this.is_selectable(stt_dt)[0]);
while(!this.is_selectable(stt_dt)[0])
{
stt_dt = stt_dt.from_string('today + 1');
}
if (!ng.defined(this.get_selected_date(stt_dt)))
{
this.select_date(stt_dt);
}
}
this.set_start_date(stt_dt);
}
}
});
非常感谢任何帮助。提前谢谢。
更新
我尝试使用my_cal2.get_selected_date():
onLoad: function()
{
var theDate = my_cal1.get_start_date();
theDate = theDate.from_string('today + 7');
var st_dt = theDate.clone();
console.log(this.is_selectable(st_dt)[0]);
while(!this.is_selectable(st_dt)[0])
{
st_dt = st_dt.from_string('today + 1');
}
// checking if no dates are selected
if (!ng.defined(this.get_selected_date()))
{
this.select_date(st_dt);
}
this.set_start_date(st_dt);
},
这样可行,但现在所有日期都不可用,即使它们未被阻止,并且当您使用get_day_since查看两个日期之间的差异时,它也无法正常工作。
仍然需要帮助。感谢。
答案 0 :(得分:0)
是的,我能够找到答案:
onLoad: function()
{
var theDate = my_cal1.get_start_date().clone();
theDate = theDate.from_string('today + 7');
var st_dt = theDate.clone();
console.log(this.is_selectable(st_dt)[0]);
while(!this.is_selectable(st_dt)[0])
{
st_dt = st_dt.from_string('today + 1');
}
// checking if no dates are selected
if (!ng.defined(this.get_selected_date()))
{
this.select_date(st_dt);
}
var origDate = my_cal1.get_start_date();
this.set_start_date(origDate);
this.set_selected_date(st_dt);
},
感谢任何试图解决此问题的人。