2

I'm using jQuery mobile 1.3.0 and trying to style dynamic elements of a listview. I have a list defined in a pages markup and can add elements to it from an object.

<div data-role="content">
      <ul data-role="listview" id="list_logs">

      </ul>
</div>

This is then the code to read items from an object and build the list:

for(log in data.logs) {
        $('<li><h2>'+data.logs[log].date+'</h2><p>'+data.logs[log].event+'</p><p>'+data.logs[log].type+'</p></li>').appendTo('#list_logs').trigger("refresh");
}

From what I can understand from the documentation calling trigger("refresh") should style the list content but neither it or trigger("create") are doing much at all. Does anyone have any further insight into this? Thanks in advance.

EDIT: I should add that the stylesheets are in place in the document head and that adding elements statically results in correct styling.

4

1 回答 1

6

Every component has a designed function for markup enhancement, listview uses:

$('#listviewID').listview('refresh');

In case this is fully dynamically create listview, not just li elements then this line should be used:

$('#listviewID').listview().listview('refresh');

Full list and examples can be found in my other ARTICLE, to be transparent it is my blog. Or it can be found HERE.

于 2013-02-23T22:09:29.930 回答