Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh Collaspible List within dynamically created Collapsible-set

Example Code on jsFiddle: http://jsfiddle.net/MqDFt/6/

Background on this, it is a dialog window that appears, and upon the user starting to enter a search query, it displays a number of results found. Here is an example of the results that would be returned via AJAX from PHP:

<div data-role='collapsible' data-mini='true'>
    <h3>appcent.com<span style='float: right;margin-top: -16px;padding-right: 10px;'>(1)</span></h3>
    <ul data-role='listview'>
        <li><a href='adv_dns_displayResults.php?lid=87e2a2ef68c71c220d6a519ab6d668b2'><span style='float: left;'>appcent.com</span><span style='float: right;'>2012-01-30 19:02:46</span></a></li>
    </ul>
</div>
<div data-role='collapsible' data-mini='true'>
    <h3>apallen.net<span style='float: right;margin-top: -16px;padding-right: 10px;'>(2)</span></h3>
    <ul data-role='listview'>
        <li><a href='adv_dns_displayResults.php?lid=8df9e81f2245f9cae41f1e95899598b3'><span style='float: left;'>apallen.net</span><span style='float: right;'>2010-07-30 15:37:32</span></a></li>
        <li><a href='adv_dns_displayResults.php?lid=a9387b995e88c7573141451546839e96'><span style='float: left;'>apallen.net</span><span style='float: right;'>2010-07-30 15:37:32</span></a></li>
    </ul>
</div>
<div data-role='collapsible' data-mini='true'>
    <h3>aptfire.com<span style='float: right;margin-top: -16px;padding-right: 10px;'>(2)</span></h3>
    <ul data-role='listview'>
        <li><a href='adv_dns_displayResults.php?lid=7de36861bcc8a2064ce7f428cc384c8c'><span style='float: left;'>aptfire.com</span><span style='float: right;'>2011-10-13 10:29:16</span></a></li>
        <li><a href='adv_dns_displayResults.php?lid=bf8c93976d5bba46b7313b9bb990ef3c'><span style='float: left;'>aptfire.com</span><span style='float: right;'>2011-10-13 10:29:18</span></a></li>
    </ul>
</div>

The Collapsible-Set refreshes properly, yet listview does not. I have tried to refresh the list view, trigger create, and a combination of other things.

like image 684
Twisty Avatar asked Jan 24 '26 20:01

Twisty


1 Answers

Here is the correct code:

$("#pastSearchResults ul").each(function(i) {
    $(this).listview(); 
});

Notes:

  1. Use simplified selector which returns all "ul" tags under div "#pastSearchResults"
  2. The selector return a list, not just one item so iterate over it
  3. Call listview() without param "refresh" since this is the first the list is created (not old and refreshed)
like image 69
donramos Avatar answered Jan 27 '26 19:01

donramos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!