Search code examples
jqtouchjquery-mobilejquery-templates

jQuery-mobile does not play well with jQuery-tmpl?


Is there any reason why the same template and JavaScript

<script id="taskTemplate" type="text/x-jquery-tmpl">
  <li>${name}</li>
</script>

$.getJSON(url, function(data) {       
  $("#taskTemplate").tmpl(data).appendTo("#tasks");
});

would work as documented with the following jqtouch markup:

<ul class="rounded" id="tasks"></ul>

but result in the template getting rendered outside (after) the unordered list with the following jquery-mobile markup?

<div data-role="content"> 
  <ul data-role="listview" id="tasks"></ul>
</div><!-- /content -->

I realize jquery-mobile is in alpha release, but it has been working nicely so far and I'd prefer not to switch to jqtouch at this stage. Has anyone seen this behavior and found a workaround?


Solution

  • You need to call the refresh method of the listview once your templating is done.

    $("yourUl").listview("refresh"); In case .page() method has never been called you may want to do something like this.

        try { 
            $(yourUl).listview("refresh");
        } catch(e){
            // Well, nothing to do there
        }