JQM删除我的页面 [英] JQM removes my page
问题描述
JSFiddle - http://jsfiddle.net/forrest_gump/
Q73Mk / 3 /正如你所看到的,我打电话给jqm changePage()它突然被#pageIndex
删除我花了很多时间试图找出原因!?!我是愚蠢的还是jqm的bug?
请注意 pageinit
当页面准备好显示但仍然隐藏时触发,因为在该页面上还没有发生事件序列。更改页面并不会阻止这些事件发生,导致目标页面显示一段时间并恢复到上一页。
您有两种解决方案: 解决方案一:
延迟 changePage
使用 setTimeout()
确保所有的页面事件($ page),'#pageIndex',function(){$ b)被触发。
$(document).on('pagecreate',' $ b setTimeout(function(){
$ .mobile.pageContainer.pagecontainer(change,#pageLogin,{
transition:slideup
});
},100); / * 100ms或更多* /
});
注意: pageinit
被弃用,并替换为 pagecreate
。此外, $。mobile.changePage
替换为 $。mobile.pageContainer.pagecontainer(change,#page,{options}) ;
。
< hr>
-
解决方案二:
pagebeforechange
事件决定首先显示哪个页面。$(document ).on(pagebeforechange,function(e,ui){
if(ui.toPage [0] .id ==pageIndex&& typeof ui.options.fromPage ===undefined ){
$ .mobile.pageContainer.pagecontainer(change,#pageLogin,{
transition:slideup
});
e.preventDefault();
}
});
Having a very small example demonstrating my issue with jquerymobile:
JSFiddle - http://jsfiddle.net/forrest_gump/Q73Mk/3/
As you can see i call jqm changePage() and it appears for a second but the it is suddenly removed by #pageIndex
I spent a lot of time trying to find out why!?! Am I stupid or is it a jqm bug?
Note that pageinit
fires when page is ready to be shown but still hidden, as there is sequence of events that still not occurred on that page. Changing page doesn't stop those events from occuring, resulting in showing the target page for a while and reverting back to previous page.
You have two solutions for this:
Solution one:
Delay
changePage
usingsetTimeout()
to ensure that all page events are triggered.$(document).on('pagecreate', '#pageIndex', function () { setTimeout(function () { $.mobile.pageContainer.pagecontainer("change", "#pageLogin", { transition: "slideup" }); }, 100); /* 100ms or more */ });
Note:
pageinit
is deprecated and replaced withpagecreate
. Also,$.mobile.changePage
is replaced with$.mobile.pageContainer.pagecontainer("change", "#page", { options });
.
Solution two:
Listen to
pagebeforechange
event to decide which page to show first.$(document).on("pagebeforechange", function (e, ui) { if (ui.toPage[0].id == "pageIndex" && typeof ui.options.fromPage === "undefined") { $.mobile.pageContainer.pagecontainer("change", "#pageLogin", { transition: "slideup" }); e.preventDefault(); } });
这篇关于JQM删除我的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!