jQuery Mobile .listview('refresh') 不起作用 [英] jQuery Mobile .listview('refresh') not working

查看:18
本文介绍了jQuery Mobile .listview('refresh') 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

      I'm building a mobile web app with jQuery Mobile and I have a problem. I am using jQuery to parse an XML file and create list items. It builds the list, then apppends that list of <li>s to the <ul> on the page. I read that in order to get the list to be styled correctly you have to call .listview('refresh') after you append the data to refresh the list so that jQuery Mobile can set correct styling to the list.

      我的问题是列表永远不会刷新.它的样式一直不正确.难道我做错了什么?我的代码正确吗?仅供参考,我尝试了 .listview().listview('refresh') 等的各种变体.

      My problem is that the list never refreshes. It keeps getting styled incorrectly. Am I doing something wrong? Is my code correct? FYI, I have tried all kinds of variations of .listview(), .listview('refresh'), etc.

      代码:

      <script type="text/javascript">
        $(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 += "<li class='ui-li-has-thumb ui-btn ui-btn-icon-right ui-li ui-btn-up-c' role='option' data-theme='c'><img src='" + $(this).find("itunes\:image").attr("href") + "' class='ui-li-thumb'><h3 class='ui-li-heading'><a href='" + $(this).find("enclosure").attr("url") + "' class='ui-link-inherit'>" + $(this).find("title").text() + "</a></h3><p class='ui-li-desc'>" + $(this).find("itunes\:subtitle").text() + "</p></li>";
          });
          $("#podcastList").append(podcastList);
          $("#podcastList").listview('refresh');
        }
      </script>
      

      谢谢!

      推荐答案

      我遇到了这个问题,代码看起来与您的相似.我的解决方案是将刷新放入 $.ajax完成"选项.

      I ran into this problem with code looking similar to yours. My solution was to place the refresh into the $.ajax "complete" option.

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

      这篇关于jQuery Mobile .listview('refresh') 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆