ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript – jQuery Mobile showPageLoadingMsg()/ hidePageLoadingMsg()方法无法在初始页面加载

2019-07-10 01:34:32  阅读:178  来源: 互联网

标签:jquery javascript jquery-mobile


我正在使用jQuery Mobile编写一个webapp,它调用一个函数将记录加载到localStorage,并在最初创建页面时使用远程JSON文件创建一个列表视图(使用页面的live.pagecreate()事件).在这个函数的开头是jQuery Mobile方法$.mobile.showPageLoadingMsg()和$.mobile.hidePageLoadingMsg()在函数的末尾.

在初始页面创建时,不会显示加载消息(在iPhone 4上使用iOS 4.3 Safari,Chrome 13和Firefox 5).但是,我在页面上也有一个刷新按钮;此按钮清除localStorage中的关联记录,然后调用用于最初填充列表视图的相同函数.但是,当从刷新按钮调用相同的函数时,showPageLoadingMsg()和hidePageLoadingMsg()都能正常工作,并且加载屏幕会出现并按预期消失.我在这里错过了什么吗?

ETA这是代码的要点(现在不在实际代码的前面,如果你需要更多,我会把它放在今晚).我还应该提一下,我已经尝试将showPageLoadingMsg放在(document).ready中,并试图将它绑定到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
});

解决方法:

For these handlers to be invoked during the initial page
load, you must bind them before jQuery Mobile executes. This can be
done in the mobileinit handler, as described on the global config
page.

文档:

> http://jquerymobile.com/demos/1.0b2/#/demos/1.0b2/docs/api/events.html

Triggered on the page being initialized, after initialization occurs.
We recommend binding to this event instead of DOM ready() because this
will work regardless of whether the page is loaded directly or if the
content is pulled into another page as part of the Ajax navigation
system.

例:

> http://jsfiddle.net/phillpafford/mKn8Y/8/

在示例中,没有任何实时事件在初始页面加载时触发,您必须在mobileinit中配置此类操作:

> http://jquerymobile.com/demos/1.0b2/#/demos/1.0b2/docs/api/globalconfig.html

标签:jquery,javascript,jquery-mobile
来源: https://codeday.me/bug/20190710/1418740.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有