2013-02-28 59 views
0

我正在用PhoneGap編寫iPhone應用程序。我試圖解析一個Facebook RSS Feed並使用jFeed來做到這一點。我得到這個Feed,並且我可以把它顯示給用戶。但是,當涉及RSS Feed的樣式以使其看起來不錯時(使用JQuery Mobile CSS屬性),它不會考慮屬性(ul和li標記)。 有沒有一種方法使用JQuery Mobile設計RSS Feed? 這裏是我使用的代碼(的index.html):使用jquery mobile設計RSS feed

<!DOCTYPE html> 
<html> 
<head> 
<title>BDA Audencia</title> 
<meta charset="utf-8" /> 
<meta content="yes" name="apple-mobile-web-app-capable"> 
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, 
minimum-scale=1, width=device-width, height=device-height, 
target-densitydpi=device-dpi" /> 
<!-- JQUERY CSS --> 
     <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" /> 

<!-- CORDOVA - PHONE GAP --> 
<script type="text/javascript" src="cordova-2.4.0.js"></script> 
<script type="text/javascript" src="js/index.js"></script> 
<link rel="stylesheet" href="style/site.css"> 

<!-- RSS FEED --> 
<script type="text/javascript" src="js/jquery.jfeed.pack.js"></script> 
     <script> 

      jQuery(function() { 

       jQuery.getFeed({ 
           url: 'http://www.facebook.com/feeds/page.php?id=360453900718092&format=atom10', 
           success: function(feed) { 


           var html = ''; 

           for(var i = 0; i < feed.items.length && i < 5; i++) { 

           var item = feed.items[i]; 

           html += '<li data-role="list-divider"><span style=" right: 45px;position: absolute; font-size: 11px; font-weight: bold; padding: .2em .5em; top: 50%; margin-top: -.95em;; right: 10px;">' 
           + item.updated 
           + '</span></li>' 
           + '<li>' 
           + item.description 
           + '</li>'; 


           } 
           html += html + ''; 
           jQuery('#result').append(html); 
           }  
           }); 
       }); 

     </script> 
    <!-- Changing the position of this code will not make $.mobile.defaultPageTransition work. DO NOT CHANGE IT --> 
    <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script> 
</head> 
<body> 


<div data-role="page" id="index"> 
<div data-role="header" data-position="fixed"> 
<h1>Test RSS</h1> 
</div> 

<div data-role="content"> 
     <div class="content-primary"> 
      <ul data-role="listview" data-theme="d" data-divider-theme="d"> 
      <div id="result"></div> 
       </ul> 
       </div> 
</div> 

<div data-role="footer" data-theme="d"> 
</div> 
</div><!-- /page one --> 

回答

1

div直接內ul是不正確的HTML結構。

<ul data-role="listview" data-theme="d" data-divider-theme="d"> 
    <div id="result"></div> 
</ul> 

請然後jQuery('#result').append(html);這個代碼後更改如下

<ul id="result" data-role="listview" data-theme="d" data-divider-theme="d"> 
</ul> 

,添加代碼以刷新列表視圖。因爲jquery移動標記是在pagecreate時生成的。在你的情況下,你是動態獲取數據並建立列表視圖。所以,你必須通過uisng應低於.listview("refresh")

修改代碼以刷新列表視圖:

$('#result').append(html); 
$('#result').listview("refresh"); 

更多關於jQuery Mobile的列表視圖。
參考:http://jquerymobile.com/demos/1.2.0/docs/lists/lists-methods.html

+0

非常感謝!我使用了你提供的代碼,它現在可以工作;) – David 2013-02-28 20:15:11