简体   繁体   中英

jQuery-mobile : force jquery mobile initialization?

I'm developing a web site with jquery mobile. My main page displays a list of items, but I catch those items with an ajax function, and then build HTML document in javascript

The problem is that jQuery Mobile initialize the page before I can modify the page, so the page doesn't look in jqm style. How can I force jqm to 'rebuild' the page after my modifications ?

Thanks

If you want to be able to adjust the DOM before the JQuery Mobile initialization occurs I suggest you do the following:

$('#YourPagesId').live('pagebeforecreate',function(event){
  // All of your DOM modification goodness here.
});

If you want to modify the DOM after the initial JQuery Mobile initialization has occurred then you would need to fire the appropriate event.

(The examples below are with a list view)

On creation of a new list view do the following:

$('#ListViewsId').listview();

If you are just modifying an already initialized listview do this:

$('#ListViewsId').listview('refresh');

More information about the available event like 'pagebeforecreate' can be found here: JQuery Mobile Events

More informration on how to initialize and refresh a JQuery Mobile Widget can be found here: Create vs. refresh: An important distinction

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM