jQuery Mobile的 - 附加HTML内容和应用jQuery Mobile的款式款式、内容、jQuery、Mobile

2023-09-11 00:55:36 作者:少年的泪不及海水蓝

我有被从XML提要附加数据创建一个移动网站。进料和它的所有的数据被加载最初,然后适当的进料含量为从阵列取出作为用户浏览该网站。的previous内容从股利清除,且新的内容被应用。我想,在追加新的内容,调用某种update()函数来jQuery Mobile的,所以它会更新哈希值,应用适当的课程,等等,但我似乎无法找到此文档中。我在这里看到这篇文章:

Dynamically创建使用jQuery Mobile的网页jQuery的模板

但我找不到任何相关文档的页面()函数,它似乎并没有为我工作。任何想法如何做到这一点?

解决方案

看看的的最新的文档和演示页面

  

加强新的标记   该页面插件分派pagecreate   事件,其中大部分部件用于自动初始化自身。只要   作为一个小窗口插件脚本被引用时,它会自动提升   该窗口小部件的任何情况下,它找到的页面上。

     

不过,如果您通过生成新标记的客户端或负载的内容   Ajax和注入到一个页面上,你可以触发创建事件   办理自动初始化包含在所有的插件   新的标记。这可以任何元素(甚至在网页触发   DIV本身),为您节省了手动初始化每个插件任务   (列表视图按钮,选择,等等)。

     

例如,如果HTML标记块(比如登录表单)装   通过阿贾克斯,触发创建事件来自动变换   所有的部件包含(输入和按钮在这种情况下)进   增强版本。在code为这种情况将是:

  $(...新的标记,它包含的部件......).appendTo(.UI页)触发(创造)。
 

JQuery Mobile

I have a mobile site which is created by appending data from an XML feed. The feed and all its data is loaded initially, and then the proper feed content is fetched from an array as the user navigates through the site. The previous content is cleared from the div, and the new content is applied. I am trying to, upon appending the new content, to call some sort of update() function to jquery mobile so that it will update the hashes, apply the proper classes, etc, but I can't seem to find this in the documentation. I read this post here:

Dynamically creating jQuery Mobile pages using jQuery Templates

But I can't find the page() function documented anywhere, and it doesn't seem to work for me. Any ideas how to accomplish this?

解决方案

Take a look at the latest documentation and demos page

Enhancing new markup The page plugin dispatches a "pagecreate" event, which most widgets use to auto-initialize themselves. As long as a widget plugin script is referenced, it will automatically enhance any instances of the widgets it finds on the page.

However, if you generate new markup client-side or load in content via Ajax and inject it into a page, you can trigger the create event to handle the auto-initialization for all the plugins contained within the new markup. This can be triggered on any element (even the page div itself), saving you the task of manually initializing each plugin (listview button, select, etc.).

For example, if a block of HTML markup (say a login form) was loaded in through Ajax, trigger the create event to automatically transform all the widgets it contains (inputs and buttons in this case) into the enhanced versions. The code for this scenario would be:

$( ...new markup that contains widgets... ).appendTo( ".ui-page").trigger( "create" );