本文介绍了停止jQuery mobile缓存动态页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

使用jQuery mobile时,我使用的是动态页面"模板,并根据用户输入插入了自定义内容.

With jQuery mobile I'm using a dynamic 'page' template with custom content inserted depending on user input.

这一切都可以,但是一旦页面被创建一次,它就会被缓存,如果您返回并进行新的选择,它将不会显示新的值.我尝试应用以下修复程序:

It all works, but once the page is created once it's cached and won't display the new values if you go back and make a new selection. I've tried applying the following fix:

$('#instrument').bind('pagehide', function(){
  $(this).remove();
});

确实删除了该页面,但是如果您尝试导航回该页面,它将不会重新初始化,而我只会一直被推回到我的应用程序的开头.

Which does remove the page, but if you try to navigate back to that page it won't re-initialize and I'll just keep getting pushed back to the beginning of my app.

必须使用pagebeforecreate将动态内容添加到页面中(实际的HTML似乎并不重要,因此我不会在此处包括它),否则它将不会被格式化.如果我使用pagebeforeshow,内容将不会被格式化,但是如果您返回并进行新选择,它将改变.

The dynamic content has to be added to the page using pagebeforecreate (the actual HTML doesn't seem important, so I won't include it here) otherwise it won't be formatted. If I use pagebeforeshow the content will not be formatted, but it WILL change if you go back and make a new selection.

我意识到pagebeforecreate将缓存页面,但由于内容未格式化,因此我似乎无法使用任何其他方法:(

I realize that pagebeforecreate will cache the page, but it doesn't appear that I can use any other method due to the content not formatting :(

我无法终生解决!

推荐答案

尝试使用pagebeforeshow,但在显示该页面以修复所有格式时调用page().

Try using pagebeforeshow but call page() when the page is shown to fix up all the formatting.

赞:

$('#instrument').bind('pagebeforeshow', function() {
  // Do your content insertion
});

$('#instrument').bind('pageshow', function() {
  $(this).page();
});

您可能会发现只有一半"有效(页面更新时不会更新格式),在这种情况下,您可以尝试此技巧:将页面包装在一个临时元素中,并在包装​​器上调用page().

You may find that this only "half" works (doesn't update formatting when page is updated), in which case you might try this trick: wrapping up the page in a temporary element and calling page() on the wrapper.

$('#instrument').bind('pageshow', function() {
  $(this).wrap('<div id="temporary-instrument-wrapper">');
  $('#temporary-instrument-wrapper').page();
  $(this).unwrap();
});

这篇关于停止jQuery mobile缓存动态页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 18:36