Possible Duplicate:
Refresh a section after adding HTML dynamically to jquery mobile
I'm trying to insert a dynamic list in my jQueryMobile page.
In my main page, I got an HTML ul element called "list": <ul id='list' data-role='listview'>
</ul>
Every list element contains a grid (class="ui-grid-a"
). The first div in the grid, for each element (div class="ui-block-a"
) contains an h2 description, while the second contains three buttons arranged horizontally, in a controlgroup (div class="ui-block-b" data-role="controlgroup" data-type="horizontal"
).
While the buttons render perfectly when the elements are in a static page, they render uncorrectly if I try to insert them dinamically in the page. Below, there's my code (jsfiddle here). What am I missing?
DOMElement += '<li>';
for (i = 0 ; i < length ; i++) {
if (typeof systemArray[i] !== 'undefined') {
DOMElement += '<fieldset class="ui-grid-a"> <div class="ui-block-a" style="width:60%;"> <h2 id="'
DOMElement += "system" + systemArray[i].name;
DOMElement += '">';
DOMElement += systemArray[i].name;
DOMElement += '</h2>';
DOMElement += '</div>';
DOMElement += '<div class="ui-block-b" data-role="controlgroup" data-type="horizontal" style="width:30%;">';
DOMElement += '<a href="#" class="deletebutton" data-icon="delete" data-role="button" id="';
DOMElement += 'delete|' + systemArray[i].name;
DOMElement += '" data-iconpos="notext">Cancel</a>';
DOMElement += '<a href="#" class="modifybutton" data-icon="gear" data-role="button" id="';
DOMElement += 'modify|' + systemArray[i].name;
DOMElement += '" data-iconpos="notext">Modify</a>';
DOMElement += '<a href="#" class="connectbutton" data-icon="arrow-r" data-role="button" id="';
DOMElement += 'connect|' + systemArray[i].name;
DOMElement += '" data-iconpos="notext">Connect</a>';
DOMElement += '</div>'
DOMElement += '</fieldset>';
}
}
DOMElement += '</li>';
// Needs trigger ('create') to create the icons http://jquerymobiledictionary.pl/faq.html
$("#list").html(DOMElement).trigger('create');
$("#list").listview("refresh");