JQuery UI 选项卡缓存
我正在开发 ASP .net MVC 应用程序。我有一个 JQuery UI 选项卡,其启用缓存的 Javascript 如下。
function LoadStudentDetailTabs() {
$('#tabStudentDetail').tabs({
cache: true,
spinner: '',
select: function(event, ui) {
$("#gridSpinnerStudentDetailTabs h5").text("Loading Details...");
$('#tabStudentDetail > .ui-tabs-panel').hide();
$("#gridSpinnerStudentDetailTabs").show();
},
load: function(event, ui) {
$("#gridSpinnerStudentDetailTabs").hide();
$('#tabStudentDetail > .ui-tabs-panel').show();
},
show: function(event, ui) {
$("#gridSpinnerStudentDetailTabs").hide();
$('#tabStudentDetail > .ui-tabs-panel').show();
}
});
}
我使用列表构建了三个选项卡项,例如 tab1、tab2、tab3。
现在发生的情况是,当构造选项卡时,它会启用所有选项卡项的缓存。但如何根据需要单独设置这些选项卡项的缓存。比如说(tab1缓存,tab2无缓存,tab3缓存)我只能看到一种将缓存应用于整个选项卡的方法,而不是根据需要将缓存应用于单个选项卡项目。
我还需要动态启用或禁用这些选项卡项(tab1、tab2、tab3)的缓存。我怎样才能做到这一点。任何帮助将不胜感激?
I am working in an ASP .net MVC Application. I have a JQuery UI tab whose Javascript to enable caching is as follows.
function LoadStudentDetailTabs() {
$('#tabStudentDetail').tabs({
cache: true,
spinner: '',
select: function(event, ui) {
$("#gridSpinnerStudentDetailTabs h5").text("Loading Details...");
$('#tabStudentDetail > .ui-tabs-panel').hide();
$("#gridSpinnerStudentDetailTabs").show();
},
load: function(event, ui) {
$("#gridSpinnerStudentDetailTabs").hide();
$('#tabStudentDetail > .ui-tabs-panel').show();
},
show: function(event, ui) {
$("#gridSpinnerStudentDetailTabs").hide();
$('#tabStudentDetail > .ui-tabs-panel').show();
}
});
}
I constructed three tab items using a list say tab1, tab2, tab3.
Now what happens is when the tab is contructed it enables cahing for all the tab items. But how can I individually set caching to these tab items as needed. Say (tab1 cache, tab2 no cache, tab3 cache) I can only see a way to apply caching to the entire tab rather than applying caching to individual tab items as needed.
There is also a need for me to enable or disable caching to these tab items (tab1, tab2, tab3) dynamically. How can I achieve this. any help would be appreciated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我最近也用到了这个。查看代码,它使用“cache.tabs”和 $.data 来确定选项卡是否应该被缓存。因此,您只需要抓取该元素,然后设置
$.data(a, "cache.tabs", false);
我创建了一个快速扩展来做到这一点,假设选项卡是静态的。可能存在不可预见的问题,当然可以改进。
正如您所看到的,我将旧的
load
方法分配给_load25624
,只是一些随机名称,将其保留为对象的成员,并在新的中调用它确定是否应该缓存选项卡后,使用 load
方法。用法:将为整个项目集打开缓存,并仅针对第一个项目(索引 0)关闭缓存。
I recently had a use for this as well. Looking into the code, it uses "cache.tabs" with $.data to determine if a tab should be cached. So you just need to grab the element, and set
$.data(a, "cache.tabs", false);
I created a quick extension to do just that, assuming the tabs are static. There may be unforseen issues, and can certainly be improved.
As you can see I assign the old
load
method to_load25624
, just some random name, keeping it as a member of the object, and call it in the newload
method after having determined if the tab should be cached. Usage:Will turn on cache for the entire set of items, and turn off cache for just the first item (index 0).
因此,为了简化 Eric 的分析,您可以通过在每个选项卡的锚元素中设置“cache.tabs”数据来控制每个选项卡的缓存。
然后,在第一次加载选项卡内容后,您可以启用该选项卡的缓存。我只需将其放在
$(document).ready
中:谢谢,Eric!
So, simplifying Eric's analysis, you can control the caching of each tab by setting the 'cache.tabs' data in each tab's anchor element.
Then after the tab content has been loaded for the first time, you can enable the caching for that tab. I would simply put it in the
$(document).ready
:Thanks, Eric!
试试这个
Try this
以上在 IE 中都不适合我。我必须放在
页面级别,而不是 Ajax 方法(适用于 Chrome)
所以:
以及:
None of the above worked for me in IE. I had to put
At the page level, rather than on the Ajax method (which worked for Chrome)
So:
As well as: