0

我有以下 .js 代码,但是当我测试网站时,它只显示每个中看到的措辞,但没有内容。最后我想要实现的是能够显示 5 个帖子,并在底部添加一个链接以显示更多:

$(document).ready(function(){
    url = 'http://hopexxx.com/category/daily-devotion/feed/';
    $.ajax({
        type: "GET",
        url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(url),
        dataType: 'json',
        error: function(){
            alert('Unable to load feed, Incorrect path or invalid feed');
        },
        success: function(data){
            var postlist = data.responseData.feed.entries;
            var html = '<ul data-role="listview" data-filter="true">';
            for (var i = 0; i < 5; i++) {
                html += '<li>';
                html += '<a href="#">';
                html += '<div class="entry">entry.title</div>';
                html += '<div class="entry">author</div>';
                html += '<div class="entry">publishedDate</div>';
                html += '<div class="entry">contentSnippet</div>';
                html += '</a>';
                html += '</li>';
            }
            html += '</ul>';
            $("#postlist").append(html);
            $("#postlist ul[data-role=listview]").listview();

        }});
    });
4

2 回答 2

0

在 data.responseData.feed.entries 上尝试 $.each 循环,详情请参见此处

于 2013-09-24T11:35:36.630 回答
0

如果您知道您的 postlist 不为空,并且每个条目都有属性“title”、“author”、“publishedDate”和“contentSnippet”,请尝试以下操作:

var postlist = data.responseData.feed.entries;
var html = '<ul data-role="listview" data-filter="true">';
for (var i = 0; i < 5; i++) {

    var entry = postlist[i];

    html += '<li>';
    html += '<a href="#">';
    html += '<div class="entry">' + entry.title + '</div>';
    html += '<div class="entry">' + entry.author + '</div>';
    html += '<div class="entry">' + entry.publishedDate + '</div>';
    html += '<div class="entry">' + entry.contentSnippet + '</div>';
    html += '</a>';
    html += '</li>';
}
    html += '</ul>';
    $("#postlist").append(html);
于 2013-09-24T11:38:32.837 回答