jQuery Mobile .listview(’refresh’)无效

我正在使用jQuery Mobile构建移动Web应用程序,我遇到了问题。 我使用jQuery来解析XML文件并创建列表项。 它构建列表,然后将

  • 的列表应用到页面上的
      。 我读到,为了使列表正确设置样式,您必须在附加数据以刷新列表后调用.listview('refresh') ,以便jQuery Mobile可以为列表设置正确的样式。

      我的问题是列表永远不会刷新。 它不断变换风格。 难道我做错了什么? 我的代码是否正确? 仅供参考,我已尝试过.listview() .listview('refresh')等各种变体。

      码:

        $(window).load(function() { $.ajax({ type: "GET", url: "podcast.xml", dataType: "xml", async: false, success: parseXml }); }); function parseXml(xml) { var podcastList = ""; $(xml).find("item").each(function() { podcastList += "
    • " + $(this).find("title").text() + "

      " + $(this).find("itunes\\:subtitle").text() + "

    • "; }); $("#podcastList").append(podcastList); $("#podcastList").listview('refresh'); }

      谢谢!

      我遇到了类似于你的代码遇到了这个问题。 我的解决方案是将刷新放入$ .ajax“完成”选项。

        complete: function() { $('#list-id').listview('refresh'); } 

      我的解决方案是在listview方法中不使用任何参数

       

      my playlist

      Back

      结束然后..

       $('#playlist').bind('pageshow', function () { doOnCallBack = function(){ $('#playlist').find('[data-role="listview"]').listview(); } ajaxGet('${genSecureLink(action:'updatePlaylistTemplate',controller:'ajaxActionsPd',absolute:'true')}',$('#playlist').find('[data-role="content"]'),doOnCallBack); }); 

      这是我的函数ajaxGet:

       function ajaxGet(url,target,doOnCallBack){ $.ajax({ url: url, error:function(x,e){handleAjaxError(x,e);}, beforeSend:function(){$.mobile.showPageLoadingMsg();}, complete:function(){$.mobile.hidePageLoadingMsg();doOnCallBack();}, success:function(data, textStatus, jqXHR){target.html(data);} }); } 
       $("#podcastList").trigger("create"); 

      斯派克的回答对我有用 – 我的目标是ul的父母div。 我还需要将ajax函数绑定到pagecreate – 即:

       

      Podcast List

      你的代码对我来说很好看…看起来几乎就像我在我的应用程序中所拥有的一样。

      也许问题在于你的HTML? 它应该看起来像:

       

      Podcast List