在 jQuery Mobile 中动态插入扩展器
我对 jQuery 很陌生,目前对尝试将动态创建的扩展器插入 jQuery-Mobile 页面感到绝望,如下所示:
<div data-role="page" id="myPage">
<div data-role="content">
<div id="myContainer"></div>
</div>
</div>
由于扩展器应插入“myContainer”,我正在编写:
var expander = $("<div data-role='collapsible' data-collapsed='true'><h3 class='category' /><div class='content' /></div>");
$("#myContainer").append(expander);
expander.find(".category").text(/*Some text*/);
expander.find(".content").text(/*Some text*/);
但是,只有一个无主题的并且不可折叠的 div 出现在我的文档中。
我想,我将不得不手动切换扩展器的创建,类似于刷新列表视图 - 然而,我在文档中没有找到任何相关内容。
不幸的是,两者
expander.Refresh();
//nor
expander.Expander();
似乎都不存在。
非常感谢您的回复!
I am quite new to jQuery and are currently despairing of trying to insert a dynamically created expander into a jQuery-Mobile page which looks like the following:
<div data-role="page" id="myPage">
<div data-role="content">
<div id="myContainer"></div>
</div>
</div>
As the expander should be inserted into "myContainer", I am writing:
var expander = $("<div data-role='collapsible' data-collapsed='true'><h3 class='category' /><div class='content' /></div>");
$("#myContainer").append(expander);
expander.find(".category").text(/*Some text*/);
expander.find(".content").text(/*Some text*/);
However, only a unthemed and not collapsible div appears in my document.
I guess, I will have to manually toggle the creation of the expander similar to refreshing a listview - I did not find anything about that in the documentation, however.
Unfortunately, neither
expander.Refresh();
//nor
expander.Expander();
seems to exist.
Many thanks in advance for your responses!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实上,这个问题经常重复发生,因此我创建了一个关于它的常见问题解答。
您需要在添加到 DOM 的最顶层元素上使用
.page()
。请参阅此处了解详细信息:
http://jquerymobiledictionary.dyndns.org/faq.html
[edit]
我也达到了当我想在
page*
事件中使用.page
时,解决方案对我来说相当明显 - 使用信号量。如果您不知道如何实现信号量,请参阅我的双列插件代码作为示例(它位于同一站点)
This question is in fact a duplicate happening so often that I created a FAQ about it.
You need to use
.page()
on the topmost element that you add to DOM.See here for details:
http://jquerymobiledictionary.dyndns.org/faq.html
[edit]
I have also reached the moment when I wanted to use
.page
inside apage*
event and the solution was rather obvious to me - use a semaphore.If you don't know how to implement a semaphore, see my dual column plugin code as an example (it's on the same site)