2017-04-20 97 views
0

我只想顯示一篇文章,但是當我將(0,2)更改爲(0,1)時沒有任何內容出現。有沒有快速的解決方案?僅在RSS訂閱中顯示1篇文章YUI

YUI().use('yql', function(Y){ 
 
    var query = 'select * from rss(0,2) where url = "http://rss.cnn.com/rss/money_latest.rss"' 
 
    var q = Y.YQL(query, function(r){ 
 
     //r now contains the result of the YQL Query as a JSON 
 
     var feedmarkup = '<div>' 
 
     var feed = r.query.results.item // get feed as array of entries 
 
     for (var i=0; i<feed.length; i++){ 
 
      feedmarkup += '<p><a href="' + feed[i].link + '">' 
 
      feedmarkup += feed[i].title + '</a></p>' 
 
      feedmarkup += '<p>' + feed[i].description + '</p>' \t 
 
\t \t \t feedmarkup += '<p><a href="' + feed[i].link + '">' 
 
      feedmarkup += '<span class="more">Read more</span>' + '</a></p>' \t \t 
 
     } \t \t 
 
     document.getElementById('uknews').innerHTML = feedmarkup 
 
    }) 
 
})
<script src="http://yui.yahooapis.com/3.18.1/build/yui/yui-min.js"></script> 
 
    <div id="uknews"></div>

回答

0

我找到了答案,並希望這可以幫助別人:

YUI().use('yql', function(Y) { 
 

 
    var query = 'select * from rss(0,1) where url = "http://rss.cnn.com/rss/cnn_world.rss"' 
 
    var q = Y.YQL(query, function(r) { 
 
    //r now contains the result of the YQL Query as a JSON 
 
    var feedmarkup = '<div class="news-feed">' 
 
    var feed = r.query.count > 1 ? r.query.results.item : [r.query.results.item]; // get feed as array of entries 
 
    for (var i = 0; i < feed.length; i++) { 
 
     feedmarkup += '<div class="feed-title"><a href="' + feed[i].link + '">' 
 
     feedmarkup += feed[i].title + '</a></div>' 
 
     feedmarkup += '<div class="feed-description">' + feed[i].description + '</div>' 
 
     feedmarkup += '<div class="feed-link"><a href="' + feed[i].link + '">' 
 
     feedmarkup += '<span class="more">Learn more</span>' + '</a></p>' 
 
    } 
 

 
    document.getElementById('uknews').innerHTML = feedmarkup 
 
    }) 
 
})
.feedflare { 
 
    display: none; 
 
} 
 

 
div.feed-description { 
 
    display: block; 
 
    max-width: 400px; 
 
    overflow: hidden; 
 
    white-space: nowrap; 
 
    text-overflow: ellipsis; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
<script src="http://yui.yahooapis.com/3.18.1/build/yui/yui-min.js"></script> 
 

 
<div id="uknews"></div>