简体   繁体   English

防止选项卡缓存jquery-ui

[英]Prevent tab caching jquery-ui

I have a set of tabs done using jquery-ui. 我使用jquery-ui完成了一组选项卡。 I do not want the caching of tab contents. 我不希望缓存选项卡内容。 So I am doing the following: 因此,我正在执行以下操作:

$(".leftPanel").tabs(
  {cache : false,
   ajaxOptions : {
     cache : false,
     error : function(xhr, status, index, anchor) {
               $(anchor.hash).html("Oops ... There was an error");
             }
   }
});

This works and it actually fetches the data whenever I switch the tab. 这有效,并且每当我切换选项卡时,它实际上都会获取数据。 The first tab has a jquery datatable . 第一个选项卡具有一个jquery数据表 The second tab has a form with a button which creates another datatable. 第二个选项卡具有一个带有按钮的表单,该按钮创建另一个数据表。

Now the problem happens when the datatable generated in the second tab is empty. 现在,当第二个选项卡中生成的数据表为空时,就会发生问题。 This datatable is generated correctly. 该数据表已正确生成。 But when I switch to tab1 there is a "Flash of Unstyled Content" from the previous values in datatable. 但是,当我切换到tab1时,数据表中的先前值中出现了“未样式化内容的闪烁”。 Then an alert is displayed saying "DataTables warning (table id = 'table-2'): Requested unknown parameter '1' from the data source for row 0". 然后显示一条警报,提示“ DataTables警告(表ID ='表2'):从数据源请求的第0行的未知参数'1'”。 Note this happens when the second table is empty. 请注意当第二个表为空时,会发生这种情况。 I need a fix for this problem. 我需要解决此问题。

Thanks in advance! 提前致谢!

Update: Some more information: When I hide the alert, the table in tab 1 is refreshed and shows correct information. 更新:更多信息:当我隐藏警报时,选项卡1中的表将刷新并显示正确的信息。 But the alert is annoying. 但是警报很烦人。 I need the right way to get rid of it. 我需要正确的方法来摆脱它。 Note it only happens when the table in the second tab is empty. 请注意,仅当第二个选项卡中的表为空时才会发生。

I discovered the problem was not being caused by tab caching. 我发现问题不是由选项卡缓存引起的。 I was invoking the method on all objects having a particular class whereas I should be doing it on an element having a specific id. 我正在对具有特定类的所有对象调用该方法,而我应该对具有特定ID的元素执行该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM