来自Ajax Call的JQuery Mobile动态列表

时间:2011-07-23 22:49:13

标签: jquery jquery-mobile

我有一个从$ .ajax调用创建的列表。数据注入似乎有效,但HTML没有为listView选择JQueryMobile样式。任何人都可以提供任何有关为什么会发生这种情况的见解吗?

这是Ajax Call:

    function getF(){
        // Show a loading message
        var SomeData_list = document.getElementById("SomeData_list");
        SomeData_list.innerHTML = "<li>Loading...</li>";

        var gUrl = "SomeData_list.php?;
        // Do the ajax call
        $.ajax({
          url: gUrl,
          // Callback (onsuccess)
          success: function(d, status, req){
            var json = eval('(' + d + ')');
            showSomeData(json);
          },
          // Error handler
          error: function(req, status, err){
            // Alert the user that something went wrong
            var group_list = document.getElementById("group_list");
            SomeData_list.innerHTML = "<li>An error occured. Conversations could not be loaded<br>"+status + ": " + err + "</li>";
          }
        });
      }

此代码显示信息:

    function showSomeData(json){
      var SomeData_list = document.getElementById("SomeData_list");
   SomeData_list.innerHTML = "";
    var dt =json.results; 
      if (dt.length <= 0){
        SomeData_list.innerHTML += "<li>Error Message.</li>";
      }

      else{
          for (var i=0; i<dt.length; i++){
          SomeData_list.innerHTML +=  "<ul data-role='listview' data-theme='d'><li class=\"data-role='listview' data-theme='d'\"><a href='index.html'> <img src='photo.png' width='70' /><h3>Some Stuff Here</h3><p>213</p></a></li></ul>";
        }

      }
    }

2 个答案:

答案 0 :(得分:10)

确保在填充后再刷新列表元素,否则 - 如您所见 - 未应用jQM样式:

SomeData_list.listview('refresh');

答案 1 :(得分:0)

 $('#list').trigger("create");...