当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Dynamically insert expander in jQuery Mobile

问题描述:

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!

网友答案:

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 a page* 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)

分享给朋友:
您可能感兴趣的文章:
随机阅读: