gpt4 book ai didi

jquery - 延迟 jQuery 完整日历的 JSON Feed

转载 作者:行者123 更新时间:2023-12-01 00:33:01 26 4
gpt4 key购买 nike

我注意到,如果您设置一个事件源(即您将向服务器发出 AJAX 请求)并开始快速单击下个月,它将触发每个月的请求。因此,如果我快速点击获取 5 次,5 个请求将会失败。

我怎样才能让它只在用户停止点击时才会触发。我发现这样浪费资源并且可能导致错误。

最佳答案

您对此完全正确,我已经向开发团队提出了有关此错误的信息。

http://code.google.com/p/fullcalendar/issues/detail?id=920&can=1&sort=-id&colspec=ID%20Type%20Status%20Milestone%20Summary%20Stars

我现在能想到的唯一方法是使用 viewDisaply 事件。

http://arshaw.com/fullcalendar/docs/display/viewDisplay/

并在 viewDisapy 事件中调用加载事件

http://arshaw.com/fullcalendar/docs/event_data/loading/

我现在能想到的唯一方法是执行 javascript setTimeout

var t=setTimeout( FUNCTION , TIME IN MS);

里面的超时检查是isLoading,如果为true则再次设置超时。

或者只是在 viewDisplay 函数中使用 setTimeout 设置为 500 毫秒/1 秒?创建您正在寻找的所需延迟效果,一旦超时,您可以使用 addEventSource 添加所需的源 http://arshaw.com/fullcalendar/docs/event_data/addEventSource/

日历中内置了另一个选项。

http://arshaw.com/fullcalendar/docs/event_data/lazyFetching/

此选项告诉插件缓存所有事件。因此,如果您单击下一个/下一个/上一个/上一个。它只调用ajax两次。因为前两个月的数据都被加载并缓存了。

不存在 isClicking :D 这样的东西,因为我们不知道用户是否会再次点击.. :D 因此,如果用户点击下个月两次,我们只需通过设置 setDelay 来预测这一点1 秒内。

因此,如果有人想提前 6 个月出发,他们会快速按下下一步按钮,我们可以像这样检测到。

//global var

var clicks = 0;
var isClicking = false;

//jquery on load and calender initialisation.

loading: function(bool) { if (bool)
{
clicks=0; //The source has loaded completely - user stopped clicking
}
else
{
//Still loading
}
},


viewDisplay: function(view) {
click += 1; //user has clicked- and this will grow each time he clicks before the ajax finishes.
if (click > 1) //Yea he is clicking and clicking.. so lets stop calling ajax.
{
$('#calendar').fullCalendar( 'removeEventSource', '/diaryFeed.aspx' ); //Remove the source so it stops firing on each click
setTimeout ( $('#calendar').fullCalendar( 'addEventSource', '/diaryFeed.aspx' ); , 1000 ); //Add the source again and it will load and fire loading(true) and reset our click counter
}

//Handle other view changes like month/week and date changes
},

关于jquery - 延迟 jQuery 完整日历的 JSON Feed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5766967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com