简体   繁体   English

jQuery-mobile:强制jquery移动初始化?

[英]jQuery-mobile : force jquery mobile initialization?

I'm developing a web site with jquery mobile. 我正在使用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 我的主页面显示了一个项目列表,但是我使用ajax函数捕获这些项目,然后在javascript中构建HTML文档

The problem is that jQuery Mobile initialize the page before I can modify the page, so the page doesn't look in jqm style. 问题是jQuery Mobile在我修改页面之前初始化页面,因此页面看起来不是jqm样式。 How can I force jqm to 'rebuild' the page after my modifications ? 如何在修改后强制jqm“重建”页面?

Thanks 谢谢

If you want to be able to adjust the DOM before the JQuery Mobile initialization occurs I suggest you do the following: 如果您希望能够在JQuery Mobile初始化发生之前调整DOM,我建议您执行以下操作:

$('#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. 如果要在初始JQuery Mobile初始化发生后修改DOM,则需要触发相应的事件。

(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 有关“pagebeforecreate”等可用事件的更多信息,请访问: 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 有关如何初始化和刷新JQuery Mobile Widget的更多信息,请参见: 创建与刷新:一个重要的区别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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