简体   繁体   English

jquery mobile - 附加 html 内容并应用 JQuery mobile 的 ZBC4150D023D6255136FD671

[英]jquery mobile - appending html content and applying JQuery mobile's styles

I have a mobile site which is created by appending data from an XML feed.我有一个移动网站,它是通过附加来自 XML 提要的数据创建的。 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.从 div 中清除之前的内容,并应用新内容。 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.我试图在附加新内容后调用某种 update() function 到 jquery 移动设备,以便它更新哈希、应用正确的类等,但我似乎无法在文档中找到它. I read this post here:我在这里读到这篇文章:

Dynamically creating jQuery Mobile pages using jQuery Templates 使用 jQuery 模板动态创建 jQuery 移动页面

But I can't find the page() function documented anywhere, and it doesn't seem to work for me.但是我在任何地方都找不到 page() function 记录,而且它似乎对我不起作用。 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.增强新标记页面插件调度一个“pagecreate”事件,大多数小部件使用它来自动初始化自己。 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.但是,如果您生成新的标记客户端或通过 Ajax 加载内容并将其注入页面,则可以触发创建事件来处理新标记中包含的所有插件的自动初始化。 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.).这可以在任何元素(甚至是页面 div 本身)上触发,从而为您节省手动初始化每个插件的任务(listview 按钮、select 等)。

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.例如,如果通过 Ajax 加载了 HTML 标记块(例如登录表单),则触发创建事件以自动将其包含的所有小部件(在本例中为输入和按钮)转换为增强版本。 The code for this scenario would be:这种情况的代码是:

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

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

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