2012-02-23 129 views
0

我使用phongap和jquery mobile來構建一個應用程序,該應用程序應該使用JSON列出wordpress博客中最近發佈的帖子,然後允許您單擊該文章,然後轉到顯示的頁面你完整的帖子。 我的代碼可以列出所有的文章,但問題是應該在div中顯示完整文章的代碼不起作用。 我有以下代碼:使用jquery mobile刷新div


<html>  
<link href="jquery-mobile/jquery.mobile-1.0a3.min.css" rel="stylesheet" type="text/css"/> 
<script src="jquery-mobile/jquery-1.5.min.js" type="text/javascript"></script> 
<script src="jquery-mobile/jquery.mobile-1.0a3.min.js" type="text/javascript"></script> 
<script src="phonegap.js" type="text/javascript"></script> 

<script> 
function onBodyLoad(){  
    document.addEventListener("deviceready",onDeviceReady,false); } 

$(function(){ 
    $.ajax({ 
     url: "http://blog.smartapplications.co.zw/?json=get_recent_posts", 
     dataType: 'jsonp', 
     success: function(json_results){ 
      console.log(json_results); 
      // Need to add UL on AJAX call or formatting of userlist is not displayed 
      $('#blogList').append('<ul data-role="listview" data-inset="true" data-theme="d" data-divider-theme="e" data-count-theme="b"></ul>'); 
      listItems = $('#blogList').find('ul'); 
      $.each(json_results.posts, function(key) { 
       html = '<h3><a href="#post_id_'+json_results.posts[key].id+'">'+json_results.posts[key].title+'</a></h3>'; 


       listItems.append('<li>'+html+'</li>'); 
      }); 
      // Need to refresh list after AJAX call 
      $('#blogList ul').listview(); 

      $.each(json_results.posts, function(key){ 
        div_html='<div data-role="page" id="#post_id_'+json_results. posts[key].id+'"><div data-role="header"><h1>'+json_results. posts[key].title +'</h1></div><div data-role="content ">'+json_results. posts[key].text+'</div></div>'; 
        $('#content_blog').html(div_html); 
        }); 

     } 
    }); 
}) 

</script> 

</head> 
<body onload = "onBodyLoad();"> 
<div data-role="page" id="page"> 
    <div data-role="header"> 
     <h1>Home</h1> 
    </div> 
    <div data-role="content"> 
     <ul data-role="listview"> 
      <li><a href="#page1">Latest Articles</a></li> 
     </ul>  
    </div> 

</div> 

<div data-role="page" id="page1"> 
    <div data-role="header"> 
     <h1>Latest Articles</h1> 
    </div> 
    <div data-role="blog_content" style="padding:0px;"> 
    <div id="blogList"></div> 
    </div> 
</div> 



<div id="content_blog" data-role="slider"> 
</div> 
</div> 
</body> 
</html> 
+0

只是一個查詢..爲什麼你使用jquery.mobile-1.0a3 .. 你應該總是使用最新的 – ghostCoder 2012-02-23 08:36:09

回答

3

嘗試做

$('#blogList ul').listview("refresh"); 

代替

$('#blogList ul').listview(); 
0

你錯了!在這裏:

$('#blogList').append('<ul data-role="listview" data-inset="true" data-theme="d" data-divider-theme="e" data-count-theme="b"></ul>'); 

關閉,那麼你將

listItems.append('<li>'+html+'</li>'); 

<li>應該<ul>標籤內。