如何在jQuery列表中显示RSS提要结果 [英] How to display rss feed results in a jquery list

查看:98
本文介绍了如何在jQuery列表中显示RSS提要结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的博客文章结果显示为jQuery移动列表.目前,所有标题,日期,作者和摘要都逐行显示,我也希望能够单击每个帖子并以移动格式直接查看内容.这是我的代码:

I would like to display my blog post results as a jQuery mobile lists. For now all the titles, date, author and snippets are appearing line by line and also I would like to be able to click on each posts and view the contents directly as a mobile format. This is my code:

$(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(xml){
            postlist = xml.responseData.feed.entries;
            //console.log(postlist);
            var data='<ul data-role="listview" data-filter="true">';
            $.each(postlist, function(idx, data) {
                $('#postlist').append('<div class="entry">' + data.title + '</div>');
                $('#postlist').append('<div class="entry">' + data.author + '</div>');
                $('#postlist').append('<div class="entry">' + data.publishedDate + '</div>');
                $('#postlist').append('<div class="entry">' + data.contentSnippet + '</div>');
                console.log(data);
            '</ul>';
            });
        }
    });
}));

html代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <script src="css/style.css"></script>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
    <script src="js/script.js"></script>
</head>
<body>

    <div id="blog" data-role="page">
    <div data-role="header" class="sys_hd" data-position="fixed" data-id="sys_header" >
        <h1>Sysads Posts</h1>
        </div><!-- header -->
        <div data-theme="c" data-role="content" id="postlist"> </div><!-- content -->
        <div data-role="footer" data-position="fixed" data-id="sys_footer" >
                    <div data-role="navbar" >
                <ul>
                    <li><a href="#blog" class="sys_ft">Home</a></li>
                    <li><a href="#blog" class="sys_ft">Disclaimer</a></li>
                </ul>
            </div><!-- navbar --> 
        </div><!-- footer --> 
    </div><!-- page -->
</body>
</html>

推荐答案

尝试一下...

$(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(xml){
            var postlist = xml.responseData.feed.entries;
            var html = '<ul data-role="listview" data-filter="true">';
            $.each(postlist, function(idx, data) {
                html += '<li>';
                html += '<a href="#">';
                html += '<div class="entry">' + data.title + '</div>';
                html += '<div class="entry">' + data.author + '</div>';
                html += '<div class="entry">' + data.publishedDate + '</div>';
                html += '<div class="entry">' + data.contentSnippet + '</div>';
                html += '</a>';
                html += '</li>';
            });
            html += '</ul>';
            $("#postlist").append(html);
            $("#postlist ul[data-role=listview]").listview();
        });
    });
});

我所做的只是将帖子包装在单独的列表项中,也包装在链接标记中.我不知道链接的URL叫什么(返回的数据中的属性是什么),因此我将其保留为#供您填写.

All I've done is wrap the posts in individual list items, and also in a link tag. I don't know what the url for the link is called (what property it is in the returned data), so I've left that as a # for you to fill in.

这是一个有效的示例...

Here's a working example...

这篇关于如何在jQuery列表中显示RSS提要结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆