从缓存动态页面停止jQuery mobile

Ric*_*ney 2 jquery caching jquery-mobile

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

这一切都有效,但是一旦页面被缓存就会创建,如果您返回并进行新选择,则不会显示新值.我尝试过应用以下修复:

$('#instrument').bind('pagehide', function(){
  $(this).remove();
});
Run Code Online (Sandbox Code Playgroud)

这会删除页面,但如果您尝试导航回该页面,它将不会重新初始化,我将继续推回到我的应用程序的开头.

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

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

我不能为我的生活搞清楚!

Dan*_*Tao 5

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

像这样:

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

$('#instrument').bind('pageshow', function() {
  $(this).page();
});
Run Code Online (Sandbox Code Playgroud)

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

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