jQuery Mobile -> Page Lifecycle?

坚强是说给别人听的谎言 提交于 2020-01-10 07:34:10

问题


Is there something like a lifecycle for jQuery Mobile pages? Like events that get fired on init, show, hide/back, or whatever events?!

Thanks in advance!


回答1:


Intro

All information found here can also be found in my blog ARTICLE, you will also find working examples.

During the page transition:

event pagebeforecreate

event pagecreate

Best event if you want to dynamically add page content and let jQuery Mobile style yout new content. Don't use it in case of ajax call, pagebefore show should be used then but all dynamically added content them must be manually enhanced.

event pageinit

It will only trigger once per page load, any return to the page will not trigger it again, unless page is manually refreshed

event pagebeforehide

event pagebeforeshow

Best event for the page manipulation

event pageremove

event pagehide

event pageshow

Only event where other graphic jQuery/javascript can be initialized and used, like graph tools or carousels

Rest of them:

event pagebeforechange

Will always trigger twice so skip it

event pagechange

Will always trigger twice so skip it

If you want to find more about this topic and how page events work overall take a look at my other ARTICLE. Or find it HERE. Just search for the chapter called Page events transition order. But also read everything anywhere.

Official documentation: http://jquerymobile.com/demos/1.2.0/docs/api/events.html




回答2:


Just like Android activity lifecycle. jQuery Mobile pages have different events. You can check out the list of events from the official documentation for jQuery Mobile 1.3.0.

  1. pagebeforechange
  2. pagebeforecreate
  3. pagebeforehide
  4. pagebeforeload
  5. pagechange
  6. pagechangefailed
  7. pagecreate
  8. pagehide
  9. pageinit
  10. pageload
  11. pageloadfailed
  12. pageremove
  13. pageshow

and much more jQuery Mobile events documentation available here

In my openion pagebeforeshow, pageshow and pagecreate are the commonly used events.



来源:https://stackoverflow.com/questions/15232532/jquery-mobile-page-lifecycle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!