jQuery Mobile:当我返回页面时动态内容不加载 [英] jQuery Mobile: Dynamic content not loading when I return to a page

查看:166
本文介绍了jQuery Mobile:当我返回页面时动态内容不加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据来自 getmovies.php 正在正常工作,并加载到 #moviesPage 第一次加载页面。但是,如果我远离 #moviesPage ,然后返回到该内容不会重新加载。页眉和页脚出现,我可以看到,未填充的< ul> 也在那里,只是没有任何动态加载的< li> s

My data from getmovies.php is working correctly and loading into #moviesPage the FIRST time I load the page. However, if I navigate away from #moviesPage and then return to it the content does not reload. The header and footer appear and I can see that the unpopulated <ul> is also there, just not any of the dynamically loaded <li>s.

我的代码如下。

My code is below. Any thoughts on how I can get my dynamic data to load when I return to a page?

$( '#moviesPage' ).live( 'pagebeforecreate',function(event){
  getMoviesList();
});

function getMoviesList() {
  $.getJSON(serviceURL + 'getmovies.php', function(data) {
    $('#moviesList li').remove();
    movies = data.items;
    $.each(movies, function(index, movie) {
      $('#moviesList').append('<li>' +
      '<img src="posters' + movie.poster + '"/>' +
      '<div class="movie-toprow"><h4>' + movie.title + '</h4>' +
      '</li>').listview('refresh');
        });
    });
}

我使用的是jQuery Mobile 1.1.0-rc.1,但是与1.0.1相同的问题。这是适用于iOS,Android和其他移动平台上的移动应用。

I'm using jQuery Mobile 1.1.0-rc.1, but was having the same issue with 1.0.1. This is for a mobile app that will be used on iOS, Android, and other mobile platforms.

奖金:现在我只想要内容重新加载但是,最终我想为每个唯一的 movieID缓存标题电影海报图片 ,但是仍然为每个< li> 提取一些动态数据(我删除了其他数据,以简化我的代码)。我不是很熟悉缓存,但想知道如何加载新的数据和缓存的数据,当页面被重新访问。我知道我可以使用 localStorage sessionStorage 标题 ,但是如何让图像重新加载,而不再向服务器发出另一个请求?

BONUS: For now I just want the content to reload. However, eventually I would like to cache the title and movie poster image for each unique movieID, but still pull some dynamic data in for each <li> (I removed this other data to simplify my code for this question). I'm not very familiar with caching, but would like to know how to load both new data and cached data when the page is revisited. I know I could use localStorage or sessionStorage for the title, but how do I make it easy for the image to be reloaded without making another request to the server?

感谢您在主要或奖励上分享的任何见解题! -Mark

Thank you for any insight you can share on my primary or bonus question! -Mark

推荐答案

转回缓存页面使用#moviesPage方法,因此,而不是index.html使用页面ID #index或#profile

to move back to a cached page use the #moviesPage method, so instead of index.html use the page Id #index or #profile

- 来自评论

这篇关于jQuery Mobile:当我返回页面时动态内容不加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆