2012-12-07 92 views
4

我突出显示了一个月中的某些日子,这取决于来自后端的数据。当我在月份或年份进行攻击时,再次打电话给阿贾克斯电话。但datepicker只显示以前的日期。我的代码如下,jquery datepicker刷新方法不起作用

$("input.dC").live('click',function() { 
$(this).datepicker({ 
showOn:'focus', 
changeMonth:'true', 
changeYear:'true', 
onChangeMonthYear:function(year,month,inst) { 
        var date = new Date(year,month-1); 
        obj.suggestDates(date); 
        $("#"+inst.id).datepicker("refresh"); 
}, 
beforeShowDay:function(date){ 
       for(i=0;i<obj.r.length;i++) { 
        var m = obj.r[i]; 
        if(date.getMonth() == m[1] && date.getDate() == m[0] && date.getFullYear() == m[2]) { return[true,"ui-state-highlight"];} 
       } 
       return[false,""]; 
} 
}).focus(); 
}); 


obj.prototype.suggestDates=function(d){ 
//ajax call here 
//obj.r=response; 
} 

回答

3

我在这里了解了这个问题。 我们需要设置异步:假的Ajax调用 是

$.ajax({async:false}); 

现在工作得很好。

+1

仅供参考,一个副作用,这将有是,如果Ajax请求需要足够长的时间,它会引起一些浏览器的那些反应迟钝的脚本对话框之一。 – kahowell

+0

哦好吧..谢谢@kahowell – SSS

0

也许这种联系是有益的:https://github.com/jtsage/jquery-mobile-datebox/issues/231

如果没有,你有没有试过做一个刷新方法的事件处理程序之外,比里面打电话了吗?

类似的东西:

// I everytime build first a getter für my jQuery-Element. So you can change your selector with changing only one method 
var getDatebox = function() { 
    return jQuery('input.dC'); 
}; 
var refreshDatebox = function() { 
    getDatebox().datebox('refresh'); 
}; 

getDatebox().on('click', function() { // don't use 'live', it's deprecated 
    jQuery(this).datepicker({ 
     [...] 
     onChangeMonthYear: function(year, month) { 
      var date = new Date(year, month-1); 
      obj.suggestDates(date); 
      refreshDatebox(); // call new function 
     }, 
     [...] 
    }); 
});