我正在写一个使用jQuery Mobile的webapp,它调用一个函数将记录加载到localStorage中,并在页面初始时从远程JSON文件创建一个listview创建(使用页面的live.pagecreate()
事件)。在此功能的开始处,jQuery Mobile方法$.mobile.showPageLoadingMsg()
和$.mobile.hidePageLoadingMsg()
处于该函数的末尾。jQuery Mobile showPageLoadingMsg()/ hidePageLoadingMsg()方法不工作在初始页面loadn
在初始页面创建时,不会显示加载消息(在带有iOS 4.3 Safari,Chrome 13和Firefox 5的iPhone 4上)。但是,我也在页面上有一个刷新按钮;此按钮清除localStorage中的相关记录,然后调用用于初始填充列表视图的相同功能。但是,当从刷新按钮调用相同功能时,showPageLoadingMsg()
和hidePageLoadingMsg()
都可以正常工作,并且加载屏幕出现并消失,因为它应该。我在这里错过了什么吗?
ETA这里是代码的要点(不是现在的实际代码,如果你需要更多,我会把它放在今晚)。我还要提到的是,我试图把showPageLoadingMsg中(文件)。就绪,并试图将其绑定到mobileinit,我也没有工作:
function loadListView(){
$.mobile.showPageLoadingMsg();
//ajax call to pull JSON
//$.each loop to load localStorage and listview
$.listview.refresh('list');
$.mobile.hidePageLoadingMsg();
}
$(#listpage).live('pagecreate', function(event){
loadListView(); // showPageLoadingMsg() and hidePageLoadingMsg do not work when the function is called here
});
function clearList(){
//for loop that clears each item in localStorage that matches the key prefix set in loadListView
}
//runs when refresh button is clicked
$('listrefresh').live('click',function(){
clearList();
loadListView(); //showPageLoadingMsg() and hidePageLoadingMsg() work when the function is called here
});
你可以编辑你的问题,并添加一些你已经尝试过的代码? –
@Phill我在上面添加了一般代码。如果需要的话,我可以稍后添加实际的代码。 – scottoliver
只是要指出,你不应该使用.click,而应该使用它。 $('listrefresh')。live('click',function(){/ *您的代码在这里* /}); 如果你碰巧正在使用jQuery的手机测试版1.使用vclick而不是点击。 – root